已知前中求后,经典模板
#include<iostream>
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
string pre,ino;
int pid;
void post(int l,int r){
int i=l;
while(ino[i]!=pre[pid]) i++;
//cout<<i<<endl;
if(i>l) {pid++; post(l,i-1);}//遍历左子树
if(i<r) {pid++; post(i+1,r);}//遍历右子树
cout<<ino[i];//处理根节点
}
int main(){
while(cin>>pre>>ino){
pid=0;
post(0,ino.length()-1);
cout<<endl;
}
return 0;
}
poj2255Tree Recovery(二叉树的遍历)
最新推荐文章于 2015-03-09 12:44:43 发布
本文介绍了一种经典的二叉树遍历算法,通过输入先序遍历和中序遍历序列来输出后序遍历序列。该算法采用递归方式实现,能够有效地处理二叉树的数据结构问题。

&spm=1001.2101.3001.5002&articleId=6758666&d=1&t=3&u=712f9bc0917d4cab80feae7797182b12)
1233

被折叠的 条评论
为什么被折叠?



