This is my size method for my binary search tree, that is meant to implement recursion to calculate the tree's size.
public int size() {
if (left != null && right != null) {
return left.size() + 1 + right.size();
}
else if (left != null && right == null) {
return left.size() + 1;
}
else if (right != null && left == null) {
return right.size() + 1;
}
else {
return 0;
}
}
First I'm wondering if this looks all right. I also got some feedback on this function that I can calculate the size of the tree with fewer if statements but I don't see how I can do that.