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

来源:互联网 发布:厦门广电网络4k机顶盒 编辑:程序博客网 时间:2024/04/29 22:56

递归求解二叉树的高度

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




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