Description
The first and middle traversal sequences of the input binary tree are output.
Input
The first line is used to input the first sequential traversal sequence of a binary tree;
The second line is the central traversal sequence of the binary tree.
Output
Output the post-order traversal sequence of the binary tree.
Sample Input
ABDCEF
BDAECF
Sample output
DBEFCA
# Include
# Include
# Define MAX 50 + 3 using namespace std; typedef char Elem_Type; typedef struct BiTree {Elem_Type data; // data struct BiTree * Lchild; // left child struct BiTree * Rchild; // right child} BiTree; // The length of the array where the element to be searched is int Search_Num (Elem_Type num, Elem_Type * array, int len) {for (int I = 0; I
Data = * front; int index = Search_Num (* front, center, len); temp-> Lchild = Resume_BiTree (front + 1, center, index ); temp-> Rchild = Resume_BiTree (front + index + 1, center + index + 1, len-index-1); return temp;} void PostOrderTraverse (BiTree * root) // post-order traversal {if (root! = NULL) {PostOrderTraverse (root-> Lchild); PostOrderTraverse (root-> Rchild); cout <
Data ;}} int main (void) {Elem_Type * preorder = new Elem_Type [MAX]; // pre-order Elem_Type * inorder = new Elem_Type [MAX]; // medium order cin> preorder; cin> inorder; BiTree * root = Resume_BiTree (preorder, inorder, strlen (inorder); PostOrderTraverse (root); cout <