早教吧作业答案频道 -->其他-->
写出由二叉树的中序遍历序列mid[1..n]和层次遍历序列lev[1..n]确定二叉树的算法
题目详情
写出由二叉树的中序遍历序列mid[1..n ]和层次遍历序列lev[1..n ]确定二叉树的算法
▼优质解答
答案和解析
#include
#include
#define max 100
typedef char ch[10];
void fun(ch x,ch y){
if(*x){
ch x1,x2,y1,y2;
char *p,*q,*t; char r; int n=0;
r=*x; t=y; p=y1; q=y2;
while(*t!=r){
*(p++)=*(t++);
n++;
}
t++; *p='\0';
while(*t) *(q++)=*(t++);
*q='\0'; t=&x[1]; p=x1; q=x2;
for (int i=0;i while(*t) *(q++)=*(t++); *q='\0';
fun(x1,y1); fun(x2,y2);
printf("%c",r);
}
}
void f(){
ch x,y;
printf("input a tree preorder:\n"); gets(x);
printf("input a tree midoeder:\n"); gets(y);
printf("\n");
puts(x); puts(y);
fun(x,y);
printf("\n");
}
void main(){
printf("***********Bitree************\n");
int n=1;
while(n){
f();
printf("0:break 1 :continue\n");
printf("input your select :");
scanf("%d",&n); getchar();
}
}
#include
#define max 100
typedef char ch[10];
void fun(ch x,ch y){
if(*x){
ch x1,x2,y1,y2;
char *p,*q,*t; char r; int n=0;
r=*x; t=y; p=y1; q=y2;
while(*t!=r){
*(p++)=*(t++);
n++;
}
t++; *p='\0';
while(*t) *(q++)=*(t++);
*q='\0'; t=&x[1]; p=x1; q=x2;
for (int i=0;i
fun(x1,y1); fun(x2,y2);
printf("%c",r);
}
}
void f(){
ch x,y;
printf("input a tree preorder:\n"); gets(x);
printf("input a tree midoeder:\n"); gets(y);
printf("\n");
puts(x); puts(y);
fun(x,y);
printf("\n");
}
void main(){
printf("***********Bitree************\n");
int n=1;
while(n){
f();
printf("0:break 1 :continue\n");
printf("input your select :");
scanf("%d",&n); getchar();
}
}
看了写出由二叉树的中序遍历序列mi...的网友还看了以下:
为啥我写的fortran结果算出来都是零,程序如下.programex01useimslparam 2020-04-07 …
请高手帮我看段MATLAB的程序,有几个地方不懂意思,最好能帮我每句都写个注释.此程序是huffm 2020-05-13 …
为什么这一步lingo提出我missing right parenthesis的错误 实在看不出 2020-05-14 …
●设二叉树的根为第一层,则第i层上的结点数最多有 (51) 。(51) A.2i B.2 i+1 C 2020-05-25 …
#include#definemax10#definetrue1;#definefalse0;ty 2020-06-12 …
设函数f(x)在(-∞,+∞)内具有一阶连续导数,L是上半平面(y>0)内的有向分段光滑曲线,其起 2020-06-15 …
无机化学问题!那位高手给解答一下,不胜感谢原电池(-)pt/Fe2+(1.00mol.L-1)、F 2020-07-09 …
(斐波那契数列)谁能解释一下这个程序中的“c[i]:=c[i]+a[i]+b[i];varn,i, 2020-07-23 …
3556356356+6666+9+355353+jk[u'oli[li;li;l[;/k[;/[ 2020-07-24 …
F=A+A×(1+i)+…+A×(1+i)n-1,(1)等式两边同乘以(1+i):F(1+i)=A( 2020-11-01 …