[二叉树专题]:递归求解二叉树的高度

递归求解二叉树的高度

等于左右子树的最大高度+1




template
int BinaryTree::height(nodeType *p)
{
    if( p == NULL)
    {
        return 0;
    }
    else
    {
        return 1 + max( height(p->llink),height(p->rlink)); //加上根节点1层..
    }
}
//辅助max
template
int BinaryTree::max(int x, int y)
{
    return ( x >= y ? x : y );
}






你可能感兴趣的:(递归,数据结构与算法)