#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;
}
二叉树未理解部分
发布时间 2023-11-26 12:17:20作者: 加固文明幻景