二叉树的深度

分析问题:若一颗二叉树为空,其深度为0,否则,利用其深度等于max{左子树depth,右子树depth}+1,可递归实现:

int depth(BiTree T)   //树的深度  
{  
    if(!T) return 0;  
    int d1 = depth(T -> lchild);  
    int d2 = depth(T -> rchild);  
    return (d1 > d2 ? d1 : d2) + 1;  
}  
原文地址:https://www.cnblogs.com/sooner/p/3010705.html