#include<stdio.h>
#include<stdlib.h>
struct TNode
{
int Data;
TNode* Left;
TNode* Right;
};
typedef TNode* Position;
typedef Position BinTree;
void pstorder(BinTree T)
{
if(T==NULL)
return;
else
{
pstorder(T->Left);
pstorder(T->Right);
printf("%c ",T->Data);
}
}
BinTree Translate(char*preorder,char *inorder,int len)
{
if(len==0)
return NULL;
int rootIndex=0;
struct TNode* t=new TNode;
t->Data=*preorder;
for(;rootIndex<len;rootIndex++)
{
if(inorder[rootIndex]==*preorder)
break;
}
t->Left=Translate(preorder+1,inorder,rootIndex);
t->Right=Translate(preorder+rootIndex+1,inorder+rootIndex+1,len-(rootIndex+1));
return t;
}
int main(int argc, char** argv){
char* pr="GDAFEMHZ";
char* in="ADEFGHMZ";
TNode* Tnode = new TNode;
Tnode=Translate(pr, in, 8);
pstorder(Tnode);
return 0;
}