#include <cstdio>
#include <cstring>
char in_order[10],post_order[10];
int len;
void read() {
scanf("%s%s",in_order+1,post_order+1);
len=strlen(in_order+1);
}
void bulid(int L1,int R1,int L2,int R2) {
if(L1 > R1) {
return ;
}
printf("%c",post_order[R2]);
char Root=post_order[R2];
int root_place=L1;
while(in_order[root_place] != Root) {
root_place++;
}
int cnt=root_place-L1;
bulid(L1,root_place-1,L2,L2+cnt-1);
bulid(root_place+1,R1,L2+cnt,R2-1);
}
int main(void) {
read();
bulid(1,len,1,len);
return 0;
}
标签:R2,int,root,理解,place,二叉树,L1,部分,order
From: https://www.cnblogs.com/kdlyh/p/17856715.html