根据先序遍历和中序遍历构造二叉树并实现后序遍历,那里错了,求大神指教
#include<iostream.h>#include<fstream.h>
#include<math.h>
#include<stdlib.h>
ifstream fin("input.txt",ios::in);
ofstream fout("output.txt",ios::out);
struct Lnode
{
char data;
Lnode *lchild;
Lnode *rchild;
};
void postorder(Lnode *bt)
{
if(bt)
{
postorder(bt->lchild);
postorder(bt->rchild);
fout<<bt->data;
}
}
void InitLnode(Lnode *&bt,int i,int len,int j,char *a,char *b)
{
int k;
if(i<len)
{
bt=new Lnode;
bt->data=a[j++];
bt->lchild=NULL;
bt->rchild=NULL;
}
for(k=i;k<len;++k)
{
if(b[k]==bt->data)
{
// break;
InitLnode(bt->lchild,i,k,j,a,b);
InitLnode(bt->rchild,k+1,len,j,a,b);
}
}
}
void main()
{
int m,l,i=0,j=0;
char *a,*b;
fin>>m;
a=new char[m];
b=new char[m];
for(l=0;l<m;++l)
fin>>a[l];
for(l=0;l<m;++l)
fin>>b[l];
Lnode *bt;
InitLnode(bt,i,m,j,a,b);
postorder(bt);
delete []a;
delete []b;
delete bt;
fin.close();
fout.close();
}