For a binary tree, if we know its pre-order and mid-order traversal, we can launch its tree structure to know its post-order traversal. The middle and back order traversal are known. Likewise, the former order can be obtained.
Now you only need to be smart. You can use the pre-order and mid-order traversal to find the post-order traversal.
Classic problem: Conversion in three traversal Modes
# Include <stdio. h> # include <string. h> int find (char C, char a [], int S, int e)/** // * locate the root position in the middle order. */{Int I; for (I = s; I <= E; I ++) if (a [I] = c) return I ;} /** // * pre [] indicates the starting position of the first order, pre_s indicates the starting position of the first order, and pre_e indicates the Ending position of the first order. * // ** // * Where in [] indicates the middle order, in_s indicates the starting position of the middle order, and in_e indicates the Ending position of the middle order. * // ** // * Pronum () to obtain pre [pre_s ~ Pre_e], in [in_s ~ In_e. */Void pronum (char pre [], int pre_s, int pre_e, char in [], int in_s, int in_e) {char C; int K; If (in_s> in_e) return;/** // * invalid subtree, complete. */If (in_s = in_e) {printf ("% C", in [in_s]); /** // * The Child tree is output and completed directly when it is only one node. */Return;} c = pre [pre_s];/** // * C stores the root node. */K = find (C, In, in_s, in_e);/** // locate the root node in the middle order. */Pronum (PRE, pre_s + 1, pre_s + k-in_s, In, in_s, k-1); // *** recursively solve the left subtree separated. */Pronum (PRE, pre_s + k-in_s + 1, pre_e, In, k + 1, in_e);/*** // * recursive solution splits the right subtree. */Printf ("% C", c);/** // * root node output. */} Main () {int number; char pre [1000]; char in [1000]; scanf ("% d", & number); While (number --) {scanf ("% s", & Pre); scanf ("% s", & in); pronum (PRE, 0, strlen (in)-1, in, 0, strlen (pre)-1); printf ("\ n ");}}