CSC301: More Size: Student code [7/30] Previous pageContentsNext page

    public int size () {
        if (((size (root, 0)) - 1) == -1) return 0;
        return (size (root, 0)) - 1;
    }
    private static int size (Node x, int count) {
        if (x == null) return count;
        else return size (x.left, 1) + size (x.right, 1);
    }

Is it correct?

Can it be improved?

Previous pageContentsNext page