Binary Tree Problem
Can anyone see what is wrong with this function the returns the height of a binary tree
int op::tree_height(const BNODE *mt)
if(mt == NULL) return 0;
int left = 0;
int right = 0;
if(mt -> left_child != NULL)
left = tree_height(mt -> left_child);
if(mt -> right_sibling != NULL)
right = tree_height(mt -> right_child);
if(left > right) return 1 + left;
return 1 + right;
Well, could it be that you got the names wrong? left_child and right_sibling seem rather inconsistent to me.
Maybe just a typo. Ignoring that, the function is correct.
Originally Posted by laserlight