规定只有根节点,树高为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;
}

浙公网安备 33010602011771号