爱问知识人 爱问教育 医院库

已知二叉树的前序和后序遍历,怎么求中序遍历啊?

首页

已知二叉树的前序和后序遍历,怎么求中序遍历啊?

也就是求可以确定多少种树,高手指点一下啊,C或者C  代码也行啊!

提交回答

全部答案

    2018-07-18 09:13:46
  •   按照自己的思路写的,仅供参考,
    int creat(BiTree &T, ElemType pre[],ElemType post[],int low_x,int high_x,int low_h,int high_h)
    {//根据先序序列和后序序列建立二叉链表,先序序列和后序序列存于一维数组中,四个整型变量表示数组的范围,0号单元留空,函数返回可建立二叉树的数目
    count=1;
    if(low_x>high_x || low_h >high_h) {T==NULL;return count;}
    if(low_x high_h])
    {
    T=new BiNode;
    T->data=pre。
      elem[low_x];
    }
    if(low_x 1= low_h)
    {
    if(pre [low_x 1] ! = post [high_h-1])
    {
    顺序查找pre [low_x 1]在后序序列的位置a;
    顺序查找post [high_h-1]在先序序列的位置b;
    creat(T->lchild,pre,post,low_x 1,b-1,low_h,a);
    creat(T->rchild,pre,post,b,high_x,a 1,high_h-1);
    }
    else if(pre [low_x 1] = = post [high_h-1])
    {
    count*=2;
    请选择建立左子树或右子树,左输入0,右输入1,用L_R表示
    cin>>L_R;
    if(L_R= =0)
    {
    creat(T->lchild,pre,post,low_x 1,high_x,low_h,high_h-1);
    creat(T->rchild,pre,post,1,0,1,0);
    else {
    creat(T->lchild,pre,post,1,0,1,0);
    creat(T->rchild,pre,post,low_x 1,high_x,low_h,high_h-1);
    }
    }
    if (low_x 1> high_x || high_h-1 lchild,pre,post,1,0,1,0);
    creat(T->rchild,pre,post, 1,0,1,0);
    }
    }。
      

    E***

    2018-07-18 09:13:46

类似问题

换一换

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):