第5章 树与二叉树
5.5 树与二叉树的运用
综合应用题 第8题
void Judge_AVL(BiTree bt,int &balance,int &h)
{
int bl=0,br=0,hl=0,hr=0;
if(bt==NULL)
{
balance=1;
h=0;
}
if(bt->lchild==NULL&&bt->rchild==NULL)
{
balance=1;
h=1;
}
else
{
Judge_AVL(bt->lchild,bl,hl);
Judge_AVL(bt->rchild,br,hr);
h=(hl>hr:hl,hr)+1;
if(abs(hl-hr)<2)
balance= bl&&br;
else
balance 0;
}
}