📜  bst cpp 的高度 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:53.278000             🧑  作者: Mango

代码示例1
// Find height of a tree, defined by the root node
int tree_height(Node* root) {
    if (root == NULL) 
        return 0;
    else {
        // Find the height of left, right subtrees
        left_height = tree_height(root->left);
        right_height = tree_height(root->right);
          
        // Find max(subtree_height) + 1 to get the height of the tree
        return max(left_height, right_height) + 1;
}