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

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

Is it correct?

Can it be improved?

Previous pageContentsNext page