已知前序中序求后序procedure Solve

19 查阅
已知前序中序求后序procedure Solve(pre,mid:string);var i:integer;

参考答案:

正确答案:

\r\n

begin
if (pre='''') or (mid='''') then exit;
i:=pos(pre[1],mid);
solve(copy(pre,2,i),copy(mid,1,i-1));
solve(copy(pre,i+1,length(pre)-i),copy(mid,i+1,length(mid)-i));
post:=post+pre[1]; {加上根,递归结束后post即