求二叉树深度

 

int Depth(Node *pRoot)
{
    if (!pRoot)
        return 0;

    int leftDepth = Depth(pRoot->pLeft);
    int rightDepth = Depth(pRoot->pRight);

    return (leftDepth > rightDepth) ? (leftDepth + 1) : (rightDepth + 1);
}

 

 

 

 

 

EOF

posted on 2012-12-07 14:23  kkmm  阅读(114)  评论(0编辑  收藏  举报