队列 树(层序输出二叉树)
来源:互联网 发布:java 字符串包含汉字 编辑:程序博客网 时间:2024/06/03 19:38
- // rtetre.cpp : 定义控制台应用程序的入口点。
- //
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- typedef char ElemType;
- /***********************stuct tree********************************/
- typedef struct Bitnode
- {
- ElemType data;
- struct Bitnode *lchild,*rchild;
- }Bitnode,*BitTree;//树
- /*******************the queue***************************
- ***********************************************/
- typedef struct qnode
- {struct Bitnode* Tree;//yahoo
- struct qnode *next;
- }qlink;
- typedef struct
- { qlink *front;
- qlink *rear;
- }linkqueue;
- void Init_Queue(linkqueue*LQ)
- {LQ->front=LQ->rear=new qlink;
- LQ->front->next=NULL;
- }
- int Empty_L_Queue(linkqueue LQ)
- {if(LQ.front==LQ.rear)return 1;
- else return 0;
- }
- void Push_Queue(linkqueue *LQ,BitTree T)//Push_Queue(&LQ,e)
- { qlink *p;
- p=new qlink;
- p->Tree=T;
- p->next=NULL;
- LQ->rear->next=p;
- LQ->rear=p;
- }
- int Dlete_Queue(linkqueue *LQ,BitTree &p)//Dlete_Queue(&LQ,&e)哲理的& 是关键的关键
- {qlink *temp;
- if(Empty_L_Queue(*LQ))return 0;// !!!!!!!!!!!!!!!!!!!
- temp=LQ->front->next;
- p=temp->Tree;
- LQ->front->next=temp->next;
- if(LQ->rear==temp)
- LQ->rear=LQ->front;
- delete temp;
- return 1;
- }
- int Q_Display(linkqueue LQ)//Q_Display(LQ)
- {qlink *p;
- if(Empty_L_Queue(LQ))return 0;
- p=LQ.front->next;
- while(p!=NULL)
- {cout<<p->Tree<<" ";
- p=p->next;
- }
- cout<<endl;
- return 1;
- }
- int Get_Front(linkqueue LQ,BitTree p)
- {if(Empty_L_Queue(LQ))return 0;
- p=LQ.front->next->Tree;
- return 1;
- }
- /*******************the binary Tree***************************
- ***********************************************/
- int CreatB_Tree(BitTree &T)
- {
- ElemType ch;
- ch=getchar();//
- if(ch==' ')T=NULL;
- else
- {if(!(T=new Bitnode))cout<<"Error!"<<endl;
- T->data=ch;
- CreatB_Tree(T->lchild);
- CreatB_Tree(T->rchild);
- }
- return 1;
- }
- /********************practice*************************/
- /******************By layer traversal**********************/
- int Layer_Traver_B_Tree(BitTree T)
- {BitTree p;
- linkqueue LQ;
- Init_Queue(&LQ);
- p=T;
- if(!T)return 0;
- Push_Queue(&LQ,p);
- // Push_Queue(&LQ,p->lchild);
- while(!Empty_L_Queue(LQ))
- {Dlete_Queue(&LQ,p);
- if(p)cout<<p->data<<" ";
- if(p->lchild)Push_Queue(&LQ,p->lchild);
- if(p->rchild)Push_Queue(&LQ,p->rchild);
- }
- return 1;
- }
- int main()
- {
- BitTree T;
- CreatB_Tree(T);
- Layer_Traver_B_Tree(T);
- //cout<<LQ.front->data;
- // cout<<Empty_L_Queue(LQ)<<endl;
- int m;
- cin>>m;
- cout << "Hello world!" << endl;
- return 0;
- }
- 队列 树(层序输出二叉树)
- 层序输出二叉树
- 层序输出二叉树:
- 按层输出二叉树
- 数据结构实验之二叉树五:层序遍历(二叉树+队列)
- 队列实现二叉树的层序遍历
- 数据结构实验之二叉树五:层序遍历(队列)
- 层序遍历二叉树(队列的使用)
- 按层遍历二叉树(队列实现)
- 二叉树(按层遍历——队列模拟)
- PAT-A1099. 二叉树-中序建树 层序输出
- PAT-A1102. 二叉树-翻转 层序、中序输出
- 已知中后序遍历-->建立二叉树-->层序输出
- LeetCode二叉树的层序遍历的输出
- 输出二叉树每层节点数量
- 层序遍历二叉树(C语言+循环队列)
- 实现二叉树的层序遍历,说说Java中的队列结构(实现一个Java的队列)
- 二叉树的层序遍历 使用队列和不使用队列
- TreeView控件的使用
- 用C#编写的银行取款系统
- 将Java程序作成exe文件的几种方法
- 一些Java基础测试题目
- Java中的垃圾回收机制
- 队列 树(层序输出二叉树)
- 优秀Java程序员必须了解GC的工作原理
- 栈 树
- 经典SQL语句
- Java中关于“Exception in thread "main" java.lang.NoClassDefFound Error
- Swing 学习
- Hibernate自定义产生主键方式
- Linux下安装OpenCV2.1
- c++随笔