数据结构与算法,二叉树,已知前序和中序,求后序,程序怎么设计

在线等~ 最好能加Q给我仔细解释一下思路
用C语言

#include<iostream>
#include<cstring>
using namespace std;
char str1[26],str2[26];
void func(int p,int q,int len)
{
if(len==1)
{
cout<<str1[p];
return;
}
int x=q;
while(str2[x]!=str1[p])x++;
int len1=x-q;
int len2=len-(1+x-q);

if(len1>0)func(p+1,q,len1);
if(len2>0)func(p+1+len1,x+1,len2);
cout<<str2[x];
}
int main()
{
int len=0;
while(cin>>str1>>str2)
{
len=strlen(str1);
func(0,0,len);
cout<<endl;
}
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-04-24
void Postorder(NODE* bt ) /*后序遍历二叉树*/
{
if(bt==NULL) return;
Postorder(bt->lchild);
Postorder(bt->rchild);
printf("%c",bt->data);
}
这是递归算法,还有非递归算法,不懂再问我追问

抱歉,是要编一个程序,不是一个算法

第2个回答  2012-04-24
仔细观察 中序 前序 后序 之间的关系,他们是有个关系的 仔细看看你就明白了
第3个回答  2012-04-24
有一个算法的……用递归来实现