Paul Clapham wrote:If I ignore the code and just use the fact that nodeCount() returns 1, it follows that the node used by nodeCount() has null for both its left and right nodes.
Now when I look at the code, I see that setting root.leftNode and setting root.rightNode are inside if-statements so they might not be executed. I agree with Carey's suggestion to write code which tests your tree-building, but to start with you could simply put in debugging statements to see if root.leftNode and root.rightNode are assigned values or not.
Carey Brown wrote:I'm still thinking this through, but it seems that you shouldn't be using 'root' when you are inside a recursive method. That you should be passing the current node you are working on down through the recursion.
Carey Brown wrote:Nit pick: I tend to think of a "root node" as the root of the entire tree, not the root of a branch. Why not just call it "node"?
Carey Brown wrote:Line 53: you need to leave off "root."