I'm trying to write a method that recursively finds the height of the deepest node of a tree.
my professor predefined most of the nodes and trees and I just need to fill in the method.
I get an error that says the method calculateTreeLevels is undefined for the type TreeNode.
How can I write a recursive method if I cant even call the method itself.
Can someone explain to me why it is doing this/what im doing wrong and how I might bypass this problem.
my professor predefined most of the nodes and trees and I just need to fill in the method.
Code:
public int calculateTreeLevels()
{
// ADD YOUR CODE HERE
if(root == null){
return 0;
}
else{
return 1 + max(root.leftNode.calculateTreeLevels(), root.rightNode.calculateTreeLevels());
}
}
How can I write a recursive method if I cant even call the method itself.
Can someone explain to me why it is doing this/what im doing wrong and how I might bypass this problem.