//Recursively find the Height of the tree. int BinaryTree::rHeight(TreeNode*& that) { int l, r; //Base Case if (that == NULL) { return -1; } //Alternative Cases l = 1 + rHeight(that->left); r = 1 + rHeight(that->rght); if (l >= r) return l; if (r > l) return r; cout << "Recursive Height has Failed." << endl; return -2; }
size_t TreeHelper<T>::getTreeHeight(const Node* node) { size_t lHeight(0); size_t rHeight(0); size_t height(0); if (nullptr == node) { height = 0; } else { lHeight = getTreeHeight(node->left()); rHeight = getTreeHeight(node->right()); height = max(lHeight, rHeight) + 1; } return height; }
//Find the height of the tree (# of levels - 1?) int BinaryTree::height() { return rHeight(root); }