判断完全二叉树
Posted suxinpaul
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断完全二叉树相关的知识,希望对你有一定的参考价值。
判断完全二叉树
#include<stdio.h>
#include<malloc.h>
#define OVERFLOW 0;
#define ERROR O;
#define OK 1;
typedef char TElemType;
typedef int Status;
typedef struct BiTNode
TElemType data;
struct BiTNode *lchild,*rchild;
BiTNode,*BiTree;
Status CreateBiTree(BiTree &T)
char ch;
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch==' ')T=NULL;
else
if(!(T=(BiTNode*)malloc(sizeof(BiTNode))))return OVERFLOW;
T->data=ch;
printf("请输入 %c 的左节点:\\n",T->data);
CreateBiTree(T->lchild);
printf("请输入 %c 的右节点:\\n",T->data);
CreateBiTree(T->rchild);
int fullBiTree(BiTree T)
BiTree queue[100],p;
int first=0,rear=0,bj=1,cm=1;
if(T!=NULL)
rear++;
queue[rear]=T;
while(first!=rear)
first++;
p=queue[first];
if(p->lchild==NULL)
bj=0;
if(p->rchild!=NULL) cm=0;
else
cm=bj;
rear++;queue[rear]=p->lchild;
if(p->rchild==NULL) bj=0;
else
rear++;
queue[rear]=p->rchild;
return cm;
return 1;
int main()
BiTree T;
printf("请输入树根:\\n");
CreateBiTree(T);
int cm=fullBiTree(T);
if(cm)printf("此二叉树为完全二叉树\\n");
else printf("此二叉树不是完全二叉树\\n");
return 0;
以上是关于判断完全二叉树的主要内容,如果未能解决你的问题,请参考以下文章