数据结构实验之二叉树五:层序遍历
2016-08-12 08:43
295 查看
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef struct node
{
char data;
struct node *lchild;
struct node *rchild;
}node, *tree;
char c[100];
int i;
void xianxucreat(tree &t)
{
char a;
a=c[i++];
if(a==',')
{
t=NULL;
}
else
{
t=(tree)malloc(sizeof(node));
t->data=a;
xianxucreat(t->lchild);
xianxucreat(t->rchild);
}
}
void cengxu(tree &t)
{
queue<tree>sq;
if(t)
sq.push(t);
while(!sq.empty())
{
t=sq.front();
cout<<t->data;
sq.pop();
if(t->lchild!=NULL)
{
sq.push(t->lchild);
}
if(t->rchild!=NULL)
{
sq.push(t->rchild);
}
}
}
int main()
{
int n;
tree t;
cin>>n;
while(n--)
{
i=0;
cin>>c;
xianxucreat(t);
cengxu(t);
cout<<endl;
}
return 0;
}
相关文章推荐
- SDUT 3344 数据结构实验之二叉树五:层序遍历
- 数据结构实验之二叉树五:层序遍历
- 数据结构实验之二叉树五:层序遍历
- 数据结构实验之二叉树五:层序遍历
- 数据结构实验之二叉树五:层序遍历*(层序遍历要学好
- 数据结构实验之二叉树五:层序遍历
- 数据结构实验之二叉树五:层序遍历
- 3344---数据结构实验之二叉树五:层序遍历
- 数据结构实验之二叉树五:层序遍历
- 3346--数据结构实验之二叉树五:层序遍历
- 数据结构实验之二叉树五:层序遍历(数组模拟队列)
- SDUT OJ 数据结构实验之二叉树五:层序遍历
- 数据结构实验之二叉树五:层序遍历
- 3344-->数据结构实验之二叉树五:层序遍历
- 数据结构实验之二叉树五:层序遍历
- 数据结构实验之二叉树五:层序遍历
- 数据结构实验之二叉树五:层序遍历
- 数据结构实验之二叉树五:层序遍历
- 数据结构实验之二叉树五:层序遍历
- 数据结构实验之二叉树五:层序遍历