Hi, I'm trying to complete this method for a binary search tree and recursion has never been my strong point. All it does is return the total number of nodes in the tree. I have an answer that finds it a different way, but I wanted trying to get it to work this way, if it's even possible. The method so far doesn't return the right number of nodes and I'm not sure why
public int numNodes() {
return numNodesHelper(root);
}
public int numNodesHelper(Node currNode) {
int numNodes = 0;
if (currNode == null) {
return 0;
}
if (currNode.left == null && currNode.right == null) {
return 1;
}
if (currNode.left != null)
numNodes += numNodesHelper(currNode.left);
if (currNode.right != null)
numNodes += numNodesHelper(currNode.right);
return numNodes;
}