标签:build pre nbsp ret nod 后序遍历 root data return
根据前序遍历和中序遍历序列建树:
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 }
根据后序遍历和中序遍历序列建树:
标签:build pre nbsp ret nod 后序遍历 root data return
原文地址:https://www.cnblogs.com/yy-1046741080/p/11510909.html