我的代码
#include<stdio.h>
#include<malloc.h>
#include<string.h>
typedef struct TNode *Tree;
typedef struct TNode{
char data;
Tree left;
Tree right;
}BinTree;
void PostorderTraversal( Tree BT );
Tree Chonggou(char *x,char *y,int p);
int main()
{
char a[30],b[30];
while(~scanf("%s %s",a,b))
{
Tree T;
T=Chonggou(a,b,strlen(b));
PostorderTraversal(T);
printf("\n");
}
return 0;
}
Tree Chonggou(char *x,char *y,int p)
{
Tree T;
for(int i=0;i<p;i++)
if(x[0]==y[i])
{
T=(Tree)malloc(sizeof(BinTree));
T->data=x[0];
T->left=Chonggou(x+1,y,i);
T->right=Chonggou(x+i+1,y+i+1,p-i-1);
return T;
}
return NULL;
}
void PostorderTraversal( Tree BT )
{
if(BT)
{
PostorderTraversal(BT->left);
PostorderTraversal(BT->right);
printf("%c",BT->data);
}
}