博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1020. Tree Traversals (25)
阅读量:5997 次
发布时间:2019-06-20

本文共 1852 字,大约阅读时间需要 6 分钟。

Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (<=30), the total number of nodes in the binary tree. The second line gives the postorder sequence and the third line gives the inorder sequence. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in one line the level order traversal sequence of the corresponding binary tree. All the numbers in a line must be separated by exactly one space, and there must be no extra space at the end of the line.

Sample Input:

72 3 1 5 7 6 41 2 3 4 5 6 7

Sample Output:

4 1 6 3 5 7 2
1 #include
2 #include
3 4 typedef struct TNode *Ptr; 5 typedef Ptr Bintree; 6 struct TNode 7 { 8 int data; 9 Bintree left;10 Bintree right;11 };12 int inorder[50]; //中序13 int post[50]; //后序14 void Leverorder( Bintree tree);15 Bintree Create( int in[], int post[],int n);16 int main()17 {18 int n;19 int i;20 Bintree tree;21 scanf("%d",&n);22 for( i=0; i
data = post[n-1];44 temp->left = Create( in,post,index);45 temp->right = Create( in+index+1,post+index,n-index-1);46 return temp;47 }48 49 void Leverorder( Bintree tree)50 {51 if( tree== NULL)52 return ;53 Bintree T[50];54 int i=0,j=0;55 int flag=0;56 T[j++] = tree;57 while( i
data);64 if( s->left )65 T[j++]=s->left;66 if( s->right)67 T[j++]=s->right;68 i++;69 }70 }

 

转载于:https://www.cnblogs.com/yuxiaoba/p/8578231.html

你可能感兴趣的文章
解决mysql出现"the table is full"的问题
查看>>
Linux vs BSD我们到底选择谁!
查看>>
Mariadb数据复制功能实现
查看>>
RabbitMQ相关知识
查看>>
出门必备的手机软件
查看>>
foreman架构的引入1-foreman作为自动化运维工具为什么会如此强大
查看>>
Django+Nginx+Uwsgi架构部署
查看>>
轻松识破linux内核启动过程中的“”套路“”
查看>>
asp.net获取网站路径
查看>>
集中配置
查看>>
MySQL 当记录不存在时insert,当记录存在时update
查看>>
我的友情链接
查看>>
Redis进阶实践之十九 Redis如何使用lua脚本
查看>>
sar命令报错Cannot open /var/log/sa/sadd: No such fi...
查看>>
郑大校园网怎么实现xshell连接vmware下的ubnutu
查看>>
RabbitMQ Access Control
查看>>
去大公司还是小公司? 运维人员需要有自己的选择
查看>>
让你1秒看清mysql服务器问题所在
查看>>
HA知识点
查看>>
Navicat for mysql 远程连接 mySql数据库10061错误问题
查看>>