CSC403: More Size: Student code [4/10] |
public int size() { if (root == null) return 0; return 1 + size (root); } private static int size (Node x) { int total = 0; if (x == null) return 0; if (x.left != null) total += 1 + size (x.left); if (x.right != null) total += 1 + size (x.right); return total; }
Is this correct?
Can it be improved?