SDUT OJ 数据结构实验之二叉树五:层序遍历
数据结构实验之二叉树五:层序遍历
Problem Description
已知一个按先序输入的字符序列,如abd,,eg,,,cf,,,(其中,表示空结点)。请建立二叉树并求二叉树的层次遍历序列。
Input
Output
Sample Input
2
abd,,eg,,,cf,,,
xnl,,i,,u,,
Sample Output
abcdefg
xnuli
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node
{
char c;
struct node *lt, *rt;
};
char s[100];
int i;
struct node *creat()
{
struct node *root;
root=(struct node *)malloc(sizeof(struct node));
if(s[i]==',') {i++;
return NULL;
}
else{
root->c=s[i++];
root->lt=creat();
root->rt=creat();
}
return root;
}
void ceng(struct node *root)
{
int out=0, in=0;
struct node *p[100];
p[in++]=root;
while(out<in)
{
if(p[out]){
printf("%c",p[out]->c);
p[in++]=p[out]->lt;
p[in++]=p[out]->rt;
}
out++;
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
i=0;
scanf("%s",s);
struct node *root;
root=creat();
ceng(root);
printf("\n");
}
return 0;
}
SDUT OJ 数据结构实验之二叉树五:层序遍历的更多相关文章
- SDUT OJ 数据结构实验之二叉树二:遍历二叉树
数据结构实验之二叉树二:遍历二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...
- SDUT 3344 数据结构实验之二叉树五:层序遍历
数据结构实验之二叉树五:层序遍历 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 已知一个按 ...
- SDUT 3341 数据结构实验之二叉树二:遍历二叉树
数据结构实验之二叉树二:遍历二叉树 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 已知二叉 ...
- SDUT OJ 数据结构实验之图论五:从起始点到目标点的最短步数(BFS)
数据结构实验之图论五:从起始点到目标点的最短步数(BFS) Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss P ...
- SDUT OJ 数据结构实验之二叉树八:(中序后序)求二叉树的深度
数据结构实验之二叉树八:(中序后序)求二叉树的深度 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Probl ...
- SDUT OJ 数据结构实验之二叉树七:叶子问题
数据结构实验之二叉树七:叶子问题 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...
- SDUT OJ 数据结构实验之二叉树六:哈夫曼编码
数据结构实验之二叉树六:哈夫曼编码 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...
- SDUT OJ 数据结构实验之二叉树四:(先序中序)还原二叉树
数据结构实验之二叉树四:(先序中序)还原二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem ...
- SDUT OJ 数据结构实验之二叉树三:统计叶子数
数据结构实验之二叉树三:统计叶子数 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...
随机推荐
- 有一些sql 是必须要做笔记的!!
select CONCAT(unix_timestamp(),"-",id,"-",name) as aa,age from workers; //连接字段 s ...
- windows 使用命令打开防火墙的端口
Open TCP Port 80 in Windows Firewall Using Netsh [McNeel Wiki]https://wiki.mcneel.com/zoo/zoo5netsh ...
- java定时任务实现的几种方式(Timer、Spring Task、Quartz)
Timer JDK自带的Timer类,允许调度一个TimerTask任务. Demo: /** * Timer测试类 */ public class TimerDemo { public static ...
- laravel 验证表单信息
1控制器验证 $this->validate($request,[ 'Student.name'=>'required|min:2|max:20', 'Student.age'=>' ...
- maven安装错误履历
1\:maven cannot find entry:"/src/main/java" 先删除source下的文件夹 再新建文件夹
- Android Studio 编译提示 No installed build tools found. Please install the Android build tools
添加 ANDROID_HOME=D:\Android\adt-bundle-windows\sdk 系统变量即可
- 10. Regular Expression Matching字符串.*匹配
[抄题]: Given an input string (s) and a pattern (p), implement regular expression matching with suppor ...
- mybatis 框架 的应用之四(一对一 与 一对多)
lf-driver=com.mysql.jdbc.Driver lf-url=jdbc:mysql://localhost:3306/test?allowMultiQueries=true&u ...
- 1、python与ipython的下载与安装
1.ipython的下载与安装 下载链接: wget -c https://github.com/downloads/ipython/ipython/ipython-0.13.1.tar.gz ##下 ...
- chrome浏览器-Toolbar工具条不显示
来源于<sencha touch 权威指南> ------------------------------------ 工具条按钮在chrome下不显示,不知是不支持还是代码有问题.app ...