算法:递归
分析:树的基本操作,已知前序遍历和中序遍历求后序遍历。
分析:树的基本操作,已知前序遍历和中序遍历求后序遍历。
先确定根,再在中序遍历中确定左子树和右子树。
{
ID:1011mashuo
PROG:heritage
LANG:PASCAL
}
program heritage;
var
zx,qx:ansistring;
procedure work(zx,qx:ansistring);
var
t,len:longint;
begin
if qx<>'' then
begin
len:=length(qx);
t:=pos(qx[1],zx);
work(copy(zx,1,t-1),copy(qx,2,t-1));
work(copy(zx,t+1,len-t),copy(qx,t+1,len-t));
write(qx[1]);
end;
end;
begin
assign(input,'heritage.in'); reset(input);
assign(output,'heritage.out'); rewrite(output);
readln(zx);
readln(qx);
work(zx,qx);
writeln;
close(input); close(output);
end.