代码

  1. node* create(int preL, int preR, int inL, int inR){
  2. if(preL > preR){
  3. return Null;
  4. }
  5. node* root = new node;
  6. root->data = pre[preL];
  7. for(int k = inL; k <= inR; k++){
  8. if(in[k] == pre[preL]) break;
  9. }
  10. int numLeft = k - inL;
  11. root->leftchild = create(preL + 1, preL + numLeft, inL, k - 1);
  12. root->rightchild = create(preL + numLeft + 1, preR, leftNum + 1, inR);
  13. return root;
  14. }