Esempio n. 1
0
//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;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
//Find the height of the tree (# of levels - 1?)
int BinaryTree::height() { return rHeight(root); }