The algorithm is as follows:
1) First find the root node in the sequence of order,
2) Find the root node position in the sequence, (you can divide the two fork tree into the Saozi right subtree).
3) construct the left subtree in the same way.
4) Construct the right sub-tree in the same way.
The algorithm is as follows:
binarytree* creat_node (char ch) {binarytree* root;
root = new BinaryTree;
Root->data = ch;
Root->lchild = Root->rchild = NULL;
return root; } binarytree* Mid_post_create_pre (char* mid,char*post,int N) {if (!mid| |! post| | n<0) {cout<< "input error.
"<<endl;
return NULL;
} int root_index = 0;
for (root_index = 0; Root_index < N, root_index++) {if (mid[root_index] = = Post[n-1]) {break; }} if (Root_index = = N) {cout<< "The sequence of sequences does not match the order sequence.
"<<endl;
return NULL;
} binarytree* root = This->creat_node (post[n-1]);
if (Root_index > 0) {root->lchild = Root->mid_post_create_pre (Mid,post,root_index); } if (N-root_index-1 > 0) {root->rchild = Root->mid_post_create_pre (mid+root_index+1,post+root_index,n
-ROOT_INDEX-1);
} return root; }
About binary tree construction and traversal please see my previous blog: Two construction of fork tree and its traversal algorithm
For the algorithm of constructing binary tree based on ordinal sequence and ordinal sequence, please refer to my previous blog:
Constructing binary tree based on ordinal sequence and middle sequence sequence