EricYang

Tech Spot of Eric

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

规定只有根节点,树高为1;

 

int treeHeight;
void treeHigh(Node *p, int depth)
{
    if(!p)
    {
        if(depth>treeHeight)
        {
            treeHeight=depth;
        }
        return;
    }
    treeHigh(p->lc,depth+1);
    treeHigh(p->rc,depth+1);
}

int treeHigh1(Node *p)
{
    int hl,hr;
    if(!p)
    {
        return 0;
    }
    hl=treeHigh1(p->lc);
    hr=treeHigh1(p->rc);
    return  (hl>hr?hl:hr)+1;
}

  

posted on 2012-05-04 10:09  Eric-Yang  阅读(260)  评论(0)    收藏  举报