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