#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include<conio.h>
#include<malloc.h>
#define Maxsize 100
#define OK 1
#define OVERFLOW -2
typedef char TElemType ;
typedef struct BiNode//树的存储结构
{
TElemType data;
struct BiNode * lchild ,* rchild;
}BiNode ,*BiTree;
typedef BiTree ElemType; ///存放二叉树地址的循环队列
typedef struct
{
ElemType *base;
int front;
int rear;
int EnQueue;
} SeqQueue;
typedef struct TNode
{
int data;
struct TNode *left;
struct TNode *right;
} TNode,*PTNode;
typedef struct{//栈的存储结构
struct BiNode *base[100];
int top;
}Sstack;
int InitQueue(SeqQueue &Q)//建立队列
{
Q.base=(ElemType *)malloc(Maxsize*sizeof(ElemType));
if(!Q.base)
exit(OVERFLOW);
Q.front = Q.rear =0;
return OK;
}
int EnQueue(SeqQueue &Q,ElemType e)//入队
{
if((Q.rear+1)%Maxsize==Q.front)
{
printf("满了");
return 0;
}
Q.rear = (Q.rear+1)%Maxsize;
Q.base[Q.rear]=e;
return 1;
}
int DeleQueue(SeqQueue &Q,ElemType &e)//出队
{
if(Q.front==Q.rear)
{
printf("为空咯");
return 0;
}
Q.front=(Q.front+1)%Maxsize;
e=Q.base[Q.front];
return 1;
}
int Empty(SeqQueue Q)//队列是否为空
{
if(Q.rear==Q.front)
return 1;
else return 0;
}
BiTree CreateBiTree(BiTree bt)//生成二叉树
{ char ch;
BiTree h=NULL;
ch=getch();//字符只能一个一个的读入
if(ch=='#') bt=NULL;//叶子结点用#表示
else
{
if((bt=(BiNode *)malloc(sizeof(BiNode)))==NULL)
return NULL;
bt->data=ch;
printf("Ch=%c\n",ch);
printf("构造%C的左子树\n",ch);//左子树
bt->lchild=CreateBiTree(h);
printf("构造%C的右子树\n",ch);//右子树
bt->rchild=CreateBiTree(h);
}
return(bt);
}
void MenuList()
{
printf("\n\n\n**************************\n");
printf(" 1 ------- 生成二叉树A\n");
printf(" 5 ------- 判断二叉树是否为完全二叉树\n");
printf("**************************\n");
}
int main()
{
int count=0;
int a=0;
BiTree T;
int i=100;
MenuList();
while(i!=0)
{
printf("请输入选择:");
scanf("%d" ,&i);
if (i==1)
T=CreateBiTree(NULL);
if (i==5)
{
printf("判断二叉树是否为完全二叉树:");
printf("\n") ;
}
}}
判断是否为完全二叉树求大佬帮助,帮我加一个,谢谢。
最新推荐文章于 2024-01-22 21:17:57 发布