📜  查找树的高度 - C++ 代码示例

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

代码示例2
// finding height of a binary tree in c++.
int maxDepth(node* node)  
{  
    if (node == NULL)  
        return 0;  
    else
    {  
        /* compute the depth of each subtree */
        int lDepth = maxDepth(node->left);  
        int rDepth = maxDepth(node->right);  
      
        /* use the larger one */
        if (lDepth > rDepth)  
            return(lDepth + 1);  
        else return(rDepth + 1);  
    }  
}