This type of question generally has two forms. The common point is that the central sequence is known. If there is no central sequence, a tree cannot be uniquely identified. <1> we know the Pre-and mid-order sequences of Binary Trees to solve the tree. 1. determine the root node of the tree. The root is the first element in the previous traversal of all elements in the current tree. 2. subtree of the solution tree. Locate the position of the root node in the middle-order traversal. All elements on the left of the root node are the left subtree, and all elements on the right of the root node are the right subtree. If the left or right side of the root node is empty, the subtree in this direction is empty. If both the root node and the right side are empty, the root node is already a leaf node. 3. Recursive solution tree. The left and right Subtrees are regarded as two binary trees, repeating steps 1, 2, and 3 until all nodes are located. <2> after the binary tree sequence and the middle sequence are known, the tree is solved. 1. determine the root of the tree. The root is the final element of all elements in the current tree in the Post-sequential traversal. 2. subtree of the solution tree. Locate the position of the root node in the middle-order traversal. All elements on the left of the root node are the left subtree, and all elements on the right of the root node are the right subtree. If the left or right side of the root node is empty, the subtree in this direction is empty. If both the root node and the right side are empty, the root node is already a leaf node. 3. Recursive solution tree. The left and right Subtrees are regarded as two binary trees, repeating steps 1, 2, and 3 until all nodes are located. Test Case: <1> Search in ascending order and then input in descending order: sequence in descending order: ABCDEGF: CBEGDFA output in descending order: CGEFDBA code: [cpp]/* PreIndex: subindex of the first node of the subtree in the PreArray []: subTreeLen of the first node of the subtree in the InArray: length of the string sequence of the subtree: PreArray: the first sequence array InArray: The Middle sequence array */void PreInCreateTree (BiTree & T, int PreIndex, int InIndex, int subTreeLen) {// subTreeLen <0 subtree is empty if (subTreeLen <= 0) {T = NULL; return;} else {T = (BiTree) malloc (sizeof (BiTNode )); // create a root Node T-> data = PreArray [PreIndex]; // locate the node's position in the middle sequence int index = strchr (InArray, PreArray [PreIndex])-InArray; // Number of left subtree nodes int LenF = index-InIndex; // create the left subtree PreInCreateTree (T-> lchild, PreIndex + 1, InIndex, LenF ); // number of right subtree nodes (sum point-root node-left subtree node) int LenR = subTreeLen-1-LenF; // create the right subtree PreInCreateTree (T-> rchild, preIndex + LenF + 1, index + 1, LenR) ;}/ * PreIndex: subscript InIndex: SubTreeLen in InArray [] of the first node of the ordinal sequence string subTreeLen: the length of the substring sequence in the subtree PreArray: ordinal sequence array InArray: ordinal sequence array */void PreInCreateTree (BiTree & T, int PreIndex, int InIndex, int subTreeLen) {// subTreeLen <0 subtree is empty if (subTreeLen <= 0) {T = NULL; return;} else {T = (BiTree) malloc (sizeof (BiTNode); // create the root node T-> data = PreArray [PreIndex]; // locate the node's position int index = strchr (InArray, PreArray [PreIndex])-InArray; // The number of left subtree nodes int LenF = index-InIndex; // Create the left subtree PreInCreateTree (T-> lchild, PreIndex + 1, InIndex, LenF); // The number of right subtree nodes (sum point-root node-left subtree node) int LenR = subTreeLen-1-LenF; // create the right subtree PreInCreateTree (T-> rchild, PreIndex + LenF + 1, index + 1, LenR );}} main function call: [cpp] BiTree T; PreInCreateTree (T, strlen (InArray); PostOrder (T); BiTree T; PreInCreateTree (T, strlen (InArray); PostOrder (T); <2> sequencing in descending order first input: central order sequence: CBEGDFA post order sequence: CGEFDBA output first order: ABCDEGF code: [cpp]/* PostIndex: subscript InIndex of the last node of the subtree of the sequent string in PreArray []: subTreeLen of the first node of the subtree of the ordinal string in InArray: length of the string sequence of the subtree: PostArray: InArray of the back sequence: InArray of the middle sequence */void PostInCreateTree (BiTree & T, int PostIndex, int InIndex, int subTreeLen) {// subTreeLen <0 subtree is empty if (subTreeLen <= 0) {T = NULL; return;} else {T = (BiTree) malloc (sizeof (BiTNode )); // create the root node T-> data = PostArray [PostIndex]; // locate the node's position in the central sequence int index = strchr (InArray, PostArray [PostIndex])-InArray; // Number of left subtree nodes int LenF = index-InIndex; // create the left subtree PostInCreateTree (T-> lchild, postIndex-(subTreeLen-1-LenF)-1, InIndex, LenF); // number of right subtree nodes (sum point-root node-left subtree node) int LenR = subTreeLen-1-LenF; // create the right subtree PostInCreateTree (T-> rchild, PostIndex-1, index + 1, LenR);}/* PostIndex: subindex of the last node of the subtree of the sequent string in PreArray []: subTreeLen of the first node of the subtree of the ordinal string in InArray []: subtree The length of the string sequence: PostArray: InArray: The Middle sequence array */void PostInCreateTree (BiTree & T, int PostIndex, int InIndex, int subTreeLen) {// subTreeLen <0 subtree is empty if (subTreeLen <= 0) {T = NULL; return;} else {T = (BiTree) malloc (sizeof (BiTNode )); // create the root node T-> data = PostArray [PostIndex]; // locate the position of the node in the central sequence int index = strchr (InArray, PostArray [PostIndex])-InArray; // Number of left subtree nodes int LenF = index-InIndex; // create the left subtree PostInCreateTree (T-> lchild, Po StIndex-(subTreeLen-1-LenF)-1, InIndex, LenF); // number of right subtree nodes (sum point-root node-left subtree node) int LenR = subTreeLen-1-LenF; // create the right subtree PostInCreateTree (T-> rchild, PostIndex-1, index + 1, LenR);} main function call: [cpp]? BiTree T2; PostInCreateTree (T2, strlen (PostArray)-, strlen (InArray); PreOrder (T2); BiTree T2; PostInCreateTree (T2, strlen (PostArray, strlen (InArray); PreOrder (T2); complete code: [cpp] # include <iostream> # include <string> using namespace std; // Binary Tree node typedef struct BiTNode {// data char data; // left and right child pointer struct BiTNode * lchild, * rchild;} BiTNode, * BiTree; // first-order char PreArray [101] = "ABCDEGF"; // Second-Order char In Array [101] = "CBEGDFA"; // char PostArray [101] = "CGEFDBA";/* PreIndex: subindex of the first node of the subtree in the PreArray []: subTreeLen of the first node of the subtree in the InArray: length of the string sequence of the subtree: PreArray: the first sequence array InArray: The Middle sequence array */void PreInCreateTree (BiTree & T, int PreIndex, int InIndex, int subTreeLen) {// subTreeLen <0 subtree is empty if (subTreeLen <= 0) {T = NULL; return;} else {T = (BiTree) malloc (sizeof (BiTNode )); // create the root node T-> da Ta = PreArray [PreIndex]; // locate the node's position in the middle sequence int index = strchr (InArray, PreArray [PreIndex])-InArray; // Number of left subtree nodes int LenF = index-InIndex; // create the left subtree PreInCreateTree (T-> lchild, PreIndex + 1, InIndex, LenF ); // number of right subtree nodes (sum point-root node-left subtree node) int LenR = subTreeLen-1-LenF; // create the right subtree PreInCreateTree (T-> rchild, preIndex + LenF + 1, index + 1, LenR) ;}/ * PostIndex: subscript InIndex of the last node of the subtree of the sequent string in PreArray []: ordinal character SubTreeLen: subTreeLen in InArray [], the first node of the string subtree. The length of the string sequence of the subtree. PostArray: post sequence array. InArray: ordinal sequence array */void PostInCreateTree (BiTree & T, int PostIndex, int InIndex, int subTreeLen) {// subTreeLen <0 subtree is empty if (subTreeLen <= 0) {T = NULL; return;} else {T = (BiTree) malloc (sizeof (BiTNode); // create the root node T-> data = PostArray [PostIndex]; // locate the node's position in the middle sequence int index = strchr (InArray, PostArray [PostIndex])-InArray; // The number of left subtree nodes int Len F = index-InIndex; // create the left subtree PostInCreateTree (T-> lchild, PostIndex-(subTreeLen-1-LenF)-1, InIndex, LenF ); // number of right subtree nodes (sum point-root node-left subtree node) int LenR = subTreeLen-1-LenF; // create the right subtree PostInCreateTree (T-> rchild, postIndex-1, index + 1, LenR) ;}// traverse void PreOrder (BiTree T) {if (T! = NULL) {// access the root node printf ("% c", T-> data); // access the left subnode PreOrder (T-> lchild ); // access the right subnode PreOrder (T-> rchild) ;}// traverse void PostOrder (BiTree T) {if (T! = NULL) {// access the left sub-node PostOrder (T-> lchild); // access the right sub-node PostOrder (T-> rchild ); // access the root node printf ("% c", T-> data) ;}} int main () {BiTree T; PreInCreateTree (T, strlen (InArray )); postOrder (T); printf ("\ n"); BiTree T2; PostInCreateTree (T2, strlen (PostArray)-1, 0, strlen (InArray); PreOrder (T2 ); return 0 ;}# include <iostream >#include <string> using namespace std; // Binary Tree node typedef struct BiTNode {// data char data; // left and right children Pointer struct BiTNode * lchild, * rchild;} BiTNode, * BiTree; // The first sequential char PreArray [101] = "ABCDEGF "; // The middle sequence char InArray [101] = "CBEGDFA"; // The latter sequence char PostArray [101] = "CGEFDBA";/* PreIndex: subindex of the first node of the subtree in the PreArray []: subTreeLen of the first node of the subtree in the InArray: length of the string sequence of the subtree: PreArray: the first sequence array InArray: The Middle sequence array */void PreInCreateTree (BiTree & T, int PreIndex, int InIndex, int subTreeLen) {// subTreeLen <0 subtree is empty if (subT ReeLen <= 0) {T = NULL; return;} else {T = (BiTree) malloc (sizeof (BiTNode )); // create the root node T-> data = PreArray [PreIndex]; // locate the position of the node in the central sequence int index = strchr (InArray, PreArray [PreIndex])-InArray; // Number of left subtree nodes int LenF = index-InIndex; // create the left subtree PreInCreateTree (T-> lchild, PreIndex + 1, InIndex, LenF ); // number of right subtree nodes (sum point-root node-left subtree node) int LenR = subTreeLen-1-LenF; // create the right subtree PreInCreateTree (T-> rchild, preIndex + LenF + 1, index + 1, LenR) ;}}/* PostIndex: subscript InIndex of the last node of the subtree of the sequent string in PreArray: subTreeLen: the length of the string sequence of the subtree PostArray: InArray: ordinal sequence array */void PostInCreateTree (BiTree & T, int PostIndex, int InIndex, int subTreeLen) {// subTreeLen <0 subtree is empty if (subTreeLen <= 0) {T = NULL; return;} else {T = (BiTree) malloc (sizeof (BiTNode); // create the root node T-> data = PostArray [PostIndex]; // locate the node's position in the middle sequence int index = strchr (InArr Ay, PostArray [PostIndex])-InArray; // Number of left subtree nodes int LenF = index-InIndex; // create the left subtree PostInCreateTree (T-> lchild, postIndex-(subTreeLen-1-LenF)-1, InIndex, LenF); // number of right subtree nodes (sum point-root node-left subtree node) int LenR = subTreeLen-1-LenF; // create the right subtree PostInCreateTree (T-> rchild, PostIndex-1, index + 1, LenR );}} // first traverse void PreOrder (BiTree T) {if (T! = NULL) {// access the root node printf ("% c", T-> data); // access the left subnode PreOrder (T-> lchild ); // access the right subnode PreOrder (T-> rchild) ;}// traverse void PostOrder (BiTree T) {if (T! = NULL) {// access the left sub-node PostOrder (T-> lchild); // access the right sub-node PostOrder (T-> rchild ); // access the root node printf ("% c", T-> data) ;}} int main () {BiTree T; PreInCreateTree (T, strlen (InArray )); postOrder (T); printf ("\ n"); BiTree T2; PostInCreateTree (T2, strlen (PostArray)-1, 0, strlen (InArray); PreOrder (T2 ); return 0 ;}