#include <stdio.h>
#include <malloc.h>
typedef struct BTNode
{
int data;
struct BTNode *left, *right;
}BTNode;
BTNode *creat_tree()
{
BTNode *t = NULL;
int x;
//printf ("正在建立一个新二叉树,请输入结点的值:");
scanf ("%d", &x);
if (x == 0) return NULL;
else
{
t = (BTNode *) malloc (sizeof(BTNode));
t -> data = x;
t -> left = creat_tree();
t -> right = creat_tree();
}
return t;
}
int judge(BTNode *bt)
{
if (bt == NULL) return 1;
else if (bt->left == NULL && bt->right != NULL) return 0;
else if (bt->left != NULL && bt->right == NULL) return 0;
else return judge(bt->left)&&judge(bt->right);
}
void main()
{
BTNode *bt = creat_tree();
int a = judge (bt);
if (a == 1)
printf("该二叉树是满二叉树\n");
else
printf("该二叉树不是满二叉树\n");
}
6.49 编写算法判定给定二叉树是否为满二叉树
最新推荐文章于 2021-10-09 00:21:13 发布