CSC403: More Size: Student code [5/10] Previous pageContentsNext page

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

Is it correct?

Can it be improved?

Previous pageContentsNext page