Traversing contribution according to the preamble sequence / order and post-order traversal

The contribution traversal sequence preorder traversal order and:

 1 // 先序序列pre[preL,preR],中序序列in[inL,inR]
 2 node* BuildTree(int preL,int preR,int inL,int inR){
 3     if(preL>preR){
 4         return NULL;
 5     }
 6     node *root=new node;
 7     root->data=pre[preL];
 8     int k;
 9     for(k=inL;in[k]!=pre[preL];k++){
10         ;
11     }
12     root->left=BuildTree(preL+1,preL+k-inL,inL,k-1);
13     root->right=BuildTree(preL+k-inL+1,preR,k+1,inR);
14 
15     return root; // 返回
16 }

 


 


The traversal sequence achievements and postorder sequence:

 

Guess you like

Origin www.cnblogs.com/yy-1046741080/p/11510909.html