I have one additional problem can someone tell me if I did this one right and I should be done...

The worst case number of comparisons in searching a bst is equal to its height - the number of levels in a tree. Write a recursive member function height() for class template BST to determine the height of the BST.

int BST::TREE_HEIGHT(TreeNode tn){
//Empty node is simple case
if (tn==NULL)
{
return 0;
}
else //Otherwise, use recursion
{
return 1 + max(TREE_HEIGHT(tn.leftChild), TREE_HEIGHT(tn.rightChild));
}
}

Best solution: Create some BSTs, calculate their correct height by careful thought, test that your method gives you the expected answer.

Just looking at it, I'd say your code gives you the right answer, but it works hard to do so. You might consider whether there is a way to do this that doesn't visit every node. (For instance, you might consider the programming truism that you can always trade time for space and vice versa)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.