判断是否为满二叉树

#include
#include
typedef struct BiTNode{
	char data;
	struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree; 
int Full(BiTree &bt){
	//判断是否为满二叉树 
	if(bt){
		if(bt->lchild==NULL&&bt->rchild==NULL)
			return 1;
		else if(bt->lchild==NULL||bt->rchild==NULL)
			return 0;
			else 
				return (Full(bt->lchild)&&Full(bt->rchild));
	}
}
void CreatBiTree(BiTree &bt){
	//构造二叉树
	char ch;
	ch=getchar();
	if(ch=='#')
		bt=NULL;
	else{
		bt=(BiTree)malloc(sizeof(BiTNode));
		bt->data=ch;
		CreatBiTree(bt->lchild);
		CreatBiTree(bt->rchild);
	} 
} 
int main(){
	int flag;
	BiTree bt;
	CreatBiTree(bt);
	flag=Full(bt);
	printf("判断是否为满二叉树:\n");
	if(flag==1){
		printf("是!\n");
	}
	else
		printf("否!\n");
	return 0;
}

你可能感兴趣的:(数据结构)