判断排序树和平衡树

int predata=-32767;
int JudgeBST(BiTree T){
	int b1,b2;
	if(T==NULL)return 1;
	else{
		b1=JudgeBST(T->lchild);
		if(b1==0||predata>=T->data)return 0;
		predata=T->data;
		b2=JudgeBST(T->rchild);
		return b2;
	}
}

void JudgeAVL(BiTree T,int &blance,int &h){
	int b1,b2,h1,h2;
	if(T==NULL){
		h=0;
		blance=1;
	}else if(T->lchild==NULL&&T->rchild==NULL){
		h=1;
		blance=1;
	}else{
		JudgeAVL(T->lchild,b1,h1);
		JudgeAVL(T->rchild,b2,h2);
		h=(h1>h2?h1:h2)+1;
		if(abs(h1-h2)<2) balance=b1&&b2;
		else balance=0;
	}
}

 

你可能感兴趣的:(判断排序树和平衡树)