已知二叉树的前序和后序遍历,怎么求中序遍历啊?
也就是求可以确定多少种树,高手指点一下啊,C或者C 代码也行啊!
按照自己的思路写的,仅供参考,
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);
}
}。
答:由于多数患者患有程度不等的口腔疾病,成年人的龋患率明显高于儿童及青少年,并且多数人还患有牙周疾患、口内不良修复物、缺牙、残冠、残根也比较多见,牙合磨耗及颞下颌关...详情>>