层序遍历二叉树(队列),已调试,C语言_队列实现二叉树遍历

其他范文 时间:2020-02-28 18:01:45 收藏本文下载本文
【www.daodoc.com - 其他范文】

层序遍历二叉树(队列),已调试,C语言由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“队列实现二叉树遍历”。

#include #include

#define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define OVERFLOW-2

typedef int Status;

typedef char TElemType;typedef struct BiTNode{

#define MAXQSIZE 100 typedef BiTree QElemType;typedef struct{

Status CreateBiTree(BiTree *T){

} char ch;

scanf(“%c”,&ch);if(ch=='#')*T=NULL;else{

} return OK;if(!(*T=(BiTNode*)malloc(sizeof(BiTNode))))exit(OVERFLOW);(*T)->data=ch;CreateBiTree(&((*T)->lchild));CreateBiTree(&((*T)->rchild));QElemType base[MAXQSIZE];int front;int rear;TElemType data;struct BiTNode *lchild,*rchild;}BiTNode,*BiTree;}SqQueue;void InitQueue(SqQueue *Q){ }

Status EnQueue(SqQueue *Q,QElemType e){

}

Status DeQueue(SqQueue *Q,QElemType *e){

}

Status QueueEmpty(SqQueue Q){

}

void Traverse(BiTree T){ SqQueue Q;BiTree p;p=T;

InitQueue(&Q);if(p)EnQueue(&Q,p);while(!QueueEmpty(Q)){ if(Q.rear==Q.front)return TRUE;return FALSE;else if(Q->front==Q->rear)return ERROR;*e=Q->base[Q->front];Q->front=(Q->front+1)%MAXQSIZE;return OK;if((Q->rear+1)%MAXQSIZE==Q->front)return ERROR;Q->base[Q->rear]=e;Q->rear=(Q->rear+1)%MAXQSIZE;return OK;Q->front=Q->rear=0;

}

{

}

} DeQueue(&Q,&p);printf(“%c”,p->data);if(p->lchild)EnQueue(&Q,p->lchild);if(p->rchild)EnQueue(&Q,p->rchild);printf(“n”);

void main()BiTree T1;CreateBiTree(&T1);Traverse(T1);

下载层序遍历二叉树(队列),已调试,C语言word格式文档
下载层序遍历二叉树(队列),已调试,C语言.doc
将本文档下载到自己电脑,方便修改和收藏。
点此处下载文档

文档为doc格式

    热门文章
      整站推荐
        点击下载本文