判断是否为满二叉树

#include<stdio.h>
#include<stdlib.h>
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;
}

    原文作者:满二叉树
    原文地址: https://blog.csdn.net/CSDN_buyi/article/details/78525012
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞