Hi;
I am new to this C++ and now, I need some help with Binary Search Tree. So, Can somebody help me to write the following functions?
1. getNodeCount(): Returns the number of nodes in the tree.
2. getLeafCount(): Returns the number of leaf nodes in the tree.
3. getTreeHeight(): Returns the height of the tree.
If you have your traversals done, this is easy.
1. Count the number of times that you call the traversal function, minus the ones called with null pointers to nodes
2. Count ONLY the calls to the traversals with null pointers, and divide by 2.
3. Only traverse to the left, and count the number of times the traversal is called, minus 1 (the null pointer call)
Eh, true. Didnt think of that. That could get a bit ugly. I would probably keep track of the height at which each node is inserted as they are inserted, and increment that value when you get to a new level.