CSC403: Tree code: Don't need the sz parameter! [17/29] |
public int size () { return size (root); } private static int size (Node x) { if (x == null) return 0; int sz = 0; sz += 1; sz += size (x.left); sz += size (x.right); return sz; }
Don't need the sz parameter!
Node x
is counted postorder, as we return.
This is true regardless of where we put sz += 1
, since
the intermediate values are not passed around.