思考
順序シーケンスループでは再び、実際には、帰りがけ順の最後のノードをルートノードを見つけます。このようなトラバーサル順序は、左と右のサブツリーを繰り返す内で操作する前に、左と右のサブツリーに分割されます。
コード
#include <bits/stdc++.h>
using namespace std;
string in,post;
void preorder(int root,int st,int ed){
if(st>ed) return;
int i;
for(i=st;i<=ed;i++) if(in[i]==post[root]) break;
cout<<post[root];
preorder(root-1-ed+i,st,i-1);//左子树
preorder(root-1,i+1,ed);//右子树
}
int main(){
cin>>in>>post;
preorder((int)in.length()-1,0,(int)in.length()-1);
return 0;
}