logo - 刷刷题
下载APP
【简答题】

阅读下列程序说明和C代码,将应填入(n)处。
【程序5说明】
设M叉树采用列表法表示,即每棵子树对应一个列表,列表的结构为:子树根结点的值部分(设为一个字符)和用“()”括起来的各子树的列表(如有子树的话),各子列表间用“,”分隔。例如下面的三叉树可用列表a(b(c,d),e,f(g,h,i))表示。
本程序输入列表,生成一棵M叉树,并由M叉树输出列表。假定输入无错误。
【程序5】
include<Stdio.h>
include<Stdlib.h>
define M 3
typedef struct node{char val;
struct node,subTree[M];
}NODE;
char buf[255],*Str=buf;
NODE * d=NULL
NODE*makeTree()/*由列表生成M叉树*/
{int k;NODE*s;
s=(1);
s->val= *Str++;
for(k=0;k<M;k++)s->subTree[k]=NULL;
if(* str='('){
k=0;
do{str++;
s->sub Tree[k]=(2);
if(*Str==')'){Str++;break;}
k=k+1;
}while((3));
}
return s;
}
void walkTree(NODE*t)/*由M又树输出列表*/
{int i;
if(t!=NULL){
(4)
if(t->subTree[0]==NULL)return;
putchar('(');
for(i=0;i<M;i++){
(5);
if(i!=M-1&&t->subTree[i+1]!=NULL)
putchar(',');
}
putchar(')');
}
}
void main()
{printf('Enter exp:');
scanf('%s',str);
d=makeTree();
walkTree(d);putchar('/n');
}

举报
参考答案:
参考解析:
.
刷刷题刷刷变学霸
举一反三

【单选题】从键盘输入一个字符串,找到其中最大的那个元素,并在该元素的后面插入字符串“(max)”。例如:输入字符串“MyFriend”,输出字符串“My(max)Friend”。按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。#include#defineN40intmain(){charstr[N],i,j=0,iMax,max,count;charinsertStr[5]={'(','m...

A.
第1处:iMax=i 第2处:str[i+5]=str[i] 第3处:str[count+5]='\0'
B.
第1处:iMax='\0' 第2处:str[i]='\0' 第3处:str[count+5]='\0'
C.
第1处:iMax='\0' 第2处:str[i+5]=str[i] 第3处:str[i+5]='\0'
D.
第1处:iMax=i 第2处:str[i+5]= '\0' 第3处:str[i+5]='\0'