// Create a tree based on the first sequence and the middle sequence and obtain the latter sequence
# Include <stdio. h>
# Include <malloc. h>
# Include <string. h>
Typedef struct tree
{
Char data;
TREE * lchild, * rchild;
} Tree, * stree;
// A --- first, B --- middle
Void create (stree & T, char * a, char * B, int num)
{
Int K;
Char * P = NULL;
If (num = 0)
T = NULL;
Else
{
P = B;
While (* P! = * A) P ++;
K = p-B;
T = (stree) malloc (sizeof (tree ));
T-> DATA = *;
// Start point of the first and middle orders, plus the number
Create (t-> lchild, A + 1, B, k );
Create (t-> rchild, A + k + 1, p + 1, num-k-1 );
}
}
Void postorder (stree T)
{
If (t)
{
Postorder (t-> lchild );
Postorder (t-> rchild );
Printf ("% C", T-> data );
}
}
Void main ()
{
Int Len;
Char A [20], B [20];
Stree T;
Printf ("Enter your first sequence:/N ");
Scanf ("% s", );
Printf ("Enter your ordinal sequence:/N ");
Scanf ("% s", B );
Len = strlen ();
Create (t, a, B, Len );
Printf ("post-order traversal:/N ");
Postorder (t );
Printf ("/N ");
}
/*
Enter your first sequence:
Abcdefg
Enter your ordinal sequence:
Cdbagf
The following is the post-order traversal:
Dcbgfea
Press any key to continue
*/