UVA536 - Tree Recovery
来源:互联网 发布:js 中隐藏控件 编辑:程序博客网 时间:2024/05/29 14:31
这个题类似于UVA699,练习先序遍历,中序,后序。
建树类似于UVA699题目的代码
#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int maxn= 100;char pre_order[maxn],ino_order[maxn],pos_order[maxn];char L[maxn],R[maxn];int n,u=0;int input(){ memset(L,0,sizeof(L)); memset(R,0,sizeof(R)); memset(pos_order,0,sizeof(pos_order)); u=0; if(!(cin>>pre_order)) return 0; cin>>ino_order; n=strlen(ino_order); return 1;}int build(int start1,int end1,int start2,int end2){ if(start1>end1) return 0; int root=pre_order[start1]; int dig=start2; while(ino_order[dig]!=root) dig++; int cnt=dig-start2; L[root]=build(start1+1,start1+cnt,start2,dig-1); R[root]=build(start1+cnt+1,end1,dig+1,end2); return root;}void list_pos_order(int root){ if(L[root]!=0) list_pos_order(L[root]); if(R[root]!=0) list_pos_order(R[root]); pos_order[u++]= root;}int main(){ while(input()){ build(0,n-1,0,n-1);// for(int i =0; i<n; i++)// printf("%c %c\n",pre_order[i],ino_order[i]);// for(int i =0 ; i<100 ;i++)// printf("%d %d %d\n",i,L[i],R[i]); list_pos_order(pre_order[0]); for(int i =0; i<n ; i++) cout<<pos_order[i]; cout<<endl; } return 0;}
0 0
- uva536 Tree Recovery
- uva536 Tree Recovery
- UVA536 - Tree Recovery
- UVa536 Tree Recovery
- uva536 Tree Recovery
- UVA536 Tree Recovery
- uva536 -- Tree Recovery
- Tree Recovery UVA536
- UVA536 - Tree Recovery(递归)
- Uva536——Tree Recovery
- 二叉树重建(Tree Recovery ,UVa536)
- uva536-Tree Recovery-二叉树遍历
- 习题6-3 UVa536 Tree Recovery(树的遍历转换)
- Uva536 Tree Recovery 【递归建树】【习题6-3】
- [UVA548]Tree[根据中序后序构建树][UVA536]Tree Recovery[根据前序中序构建树]
- 算法竞赛入门经典 第二版 习题6-3 二叉树重建 Tree Recovery uva536
- uva536
- uva536
- 使用JAVA调用中科院ICTCLAS2015分词系统
- Android 应用程序管理机制
- Normalized Cut(归一化割)
- Android解析包时出现问题
- 证券 基础知识 真题
- UVA536 - Tree Recovery
- iOS UITableViewCell重用以及自定义Cell
- Linux 的make及makefile文件格式
- golang技术随笔(二)理解goroutine
- 循环-16. 猴子吃桃问题(15)
- zoj 2027 Travelling Fee
- CCLayer层
- linux字符设备驱动程序
- cURL模拟POST请求