I an trying to find the height in a binary search tree. I figured out how to count the leaves going directly left and directly right, but cannot figure out how to get he leaves in the middle.
int BST::height(){
int tall =0;
int tall1=0;
BinNodePtr ptr=myRoot;
if (ptr->left =='\0' && ptr->right =='\0')
return tall;//up to this part I know is correct.
else {
while (ptr->left) {
ptr=ptr->left;
tall++;
}
ptr=myRoot;
while (ptr->right) {
ptr=ptr->right;
tall1++;
}
}
if (tall>tall1)
return tall;
else
return tall1;