procedure Solve(mid,post:string); var i:integer; begin if (mid='''') or (post='''') then exit; i:=pos(post[length(post)],mid); pre:=pre+post[length(post)]; {加上根,递归结束后pre即为前序遍历} solve(copy(mid,1,I-1),copy(post,1,I-1)); solve(copy(mid,I+1,length(mid)-I),copy(post,I,length(post)-i)); end;