Uva10701 Pre, in and post

解析相似树结构算法实现
本文探讨了在树结构重建算法的基础上进行微调的过程,详细介绍了如何通过改变关键步骤来解决特定问题。主要内容包括对原始算法的概述,以及具体实现细节,通过实例展示了算法的应用效果。

和Tree Recover基本类似,就改了一点而已

 1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4 
 5 string pr,in;
 6 string postorder;
 7 void process(string preord,string inord);
 8 int main()
 9 {
10     int line,order;
11     //freopen("D:\\acm.txt","r",stdin);
12     cin>>line;
13     while(line--){
14         cin>>order;
15         cin>>pr>>in;
16         postorder.clear();
17         process(pr,in);
18         cout<<postorder<<endl;
19     }
20     return 0;
21 }
22 void process(string preord,string inord){
23     int Size = preord.size();
24     if(Size>0){
25         int p = inord.find(preord[0]);
26         process(preord.substr(1,p),inord.substr(0,p));//左树
27         process(preord.substr(p + 1,Size - (p + 1)),inord.substr(p + 1,Size - (p + 1)));//右树
28         postorder.push_back(preord[0]);
29     }
30 }

 

 
 
 
 

转载于:https://www.cnblogs.com/ohxiaobai/p/4066024.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值