//已知先序和中序建立一颗二叉树
void CreateTree(BTTree t,int[] pre,int[] in,
    int l1,int h1,int l2,int h2){//l1 为先序数组的第一个,h1 为先序数组的最后一个
    int i;
    T=(BTNode*)malloc(sizeof(BTNode));
    T->data=pre[l1];//
    for(i=l2;i<=h2;i++){
        if(pre[l1]==in[i]) break;
    }
    if(i==l2) t->lchild=null;
    else{
        CreateTree(t->lchild,pre,in,l1+1,l1+i-l2,l2,i-1);
    }
    if(i==h2) T->rchild=null;
    else{
        CreateTree(T->rchild,pre,in,l1+i-l2+1,h1,i+1,h2);
    }
}

相关文章:

  • 2022-12-23
  • 2022-01-09
  • 2021-12-19
  • 2022-01-23
  • 2021-12-14
  • 2021-11-03
  • 2021-07-27
  • 2021-08-19
猜你喜欢
  • 2021-06-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
相关资源
相似解决方案