CSC301: Storage: Is this correct? [6/8] Previous pageContentsNext page

    public int size () {
        return size (root);
    }
    private int sz = 0;
    private int size (Node x) {
        if (x == null) return sz;
        sz = sz + 1;
        size (x.left);
        size (x.right);
        return sz;
    }

A variation without static. Still wrong for the same reason.

Here is a trace of an execution.

Previous pageContentsNext page