数据结构-二叉树(4)利用前序序列和中序序列唯一确定二叉树

确定方法:

template <class T>
BinTreeNode<T> *createBinaryTree(T *VLR,T *LVR,int n){
    if(n==0) return NULL;
    int k=0;
    while (VLR[0]!=LVR[k]) k++;
    BinTreeNode<T> *t=new BinTreeNode<T>(VLR[0]);
    t->leftChild=createBinaryTree(VLR+1,LVR,k);
    t->rightChild=createBinaryTree(VLR+k+1,LVR+k+1,n-k-1);
    return t;
}

 

相关文章:

  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2021-09-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
相关资源
相似解决方案