判断是否为完全二叉树求大佬帮助,帮我加一个,谢谢。

#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") ;
		}
}}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值