●试题五阅读下列程序说明和C程序,将应填入程序中(n)处的字句,写在答卷纸的对应栏内。【程序说明】本程序先从文件读入各考生的准考证号(设为整型数)及成绩,并将其存放在一棵检索二叉树上,二叉树结点的健值是成绩,每个结点带一链表,链表结点存放取得该成绩的考生的准考证号。然后,程序按中序遍历检索二叉树,从高分到低分输出结果,使每行输出成绩及其取得成绩的考生的准考证号。【程序】#include stdio.htypedef struct idnode {int id;struct idnode * next;} IdNode;typedef struct marknode {int mark;IdNode *head;struct marknode *left, *right;} MarkNode;char fname [ ]="sp07.dat";main(){ int id, mark;MarkNode *root=null;FILE *fp=fopen(fname,"r");if(!fp) {printf("file%s open error.\n", fname);exit(0);}while (!feop(fp)) {fscanf(fp,"%d%d", id, mark);btree(root, id, mark);}fclose(fp);print(root);}btree(MarkNod**mpptr, int id, int mark){ IdNode *ip;MarkNode *mp=*mpptr;if (1) {if (mark==p-mark) addIdNODE ( (2) , id);else if (markmp-mark) btree (mp-left, id, mark);else btree(mp-right, id, mark);}else{ mp=(marknode *) malloc(sizeo (marknode));mp-mark=mark;mp-left=mp-right=NULL;(3)addIdNode(mp-head, id);(4) ;}}addIdNode(IdNode **ipp, int id){IdNode *ip=*ipp;if ( (5) )addIdNode ( (6) ), id;else{ip=(IdNode *)malloc(sizeof(IdNode));sp-id=id;ip-next=NULL;(7)}}print(MarkNode *mp){ IdNode *ip, *ip0;if (mp){print (mp-left);printf("%6d:\t",mp-mark);ip=mp-head;while(ip){printf("%6d",ip-id);ip0=ip;ip=ip-next;free(ip0);}printf("\n");printf(mp-right);free(mp);}}

●试题五

阅读下列程序说明和C程序,将应填入程序中(n)处的字句,写在答卷纸的对应栏内。

【程序说明】

本程序先从文件读入各考生的准考证号(设为整型数)及成绩,并将其存放在一棵检索二叉树上,二叉树结点的健值是成绩,每个结点带一链表,链表结点存放取得该成绩的考生的准考证号。然后,程序按中序遍历检索二叉树,从高分到低分输出结果,使每行输出成绩及其取得成绩的考生的准考证号。

【程序】

#include <stdio.h>

typedef struct idnode {

int id;

struct idnode * next;

} IdNode;

typedef struct marknode {

int mark;

IdNode *head;

struct marknode *left, *right;

} MarkNode;

char fname [ ]="sp07.dat";

main()

{ int id, mark;

MarkNode *root=null;

FILE *fp=fopen(fname,"r");

if(!fp) {

printf("file%s open error.\n", fname);

exit(0);

}

while (!feop(fp)) {

fscanf(fp,"%d%d", &id, &mark);

btree(&root, id, mark);

}

fclose(fp);

print(root);

}

btree(MarkNod**mpptr, int id, int mark)

{ IdNode *ip;

MarkNode *mp=*mpptr;

if (1) {

if (mark==p->mark) addIdNODE ( (2) , id);

else if (mark>mp->mark) btree (&mp->left, id, mark);

else btree(&mp->right, id, mark);

}else

{ mp=(marknode *) malloc(sizeo (marknode));

mp->mark=mark;

mp->left=mp->right=NULL;

(3)

addIdNode(&mp->head, id);

(4) ;

}

}

addIdNode(IdNode **ipp, int id)

{IdNode *ip=*ipp;

if ( (5) )addIdNode ( (6) ), id;

else{

ip=(IdNode *)malloc(sizeof(IdNode));

sp->id=id;

ip->next=NULL;

(7)

}

}

print(MarkNode *mp)

{ IdNode *ip, *ip0;

if (mp){

print (mp->left);

printf("%6d:\t",mp->mark);

ip=mp->head;

while(ip){

printf("%6d",ip->id);

ip0=ip;

ip=ip->next;

free(ip0);

}

printf("\n");printf(mp->right);free(mp);

}

}


相关考题:

阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】StringEditor类的功能是:已知一个字符串,返回将字符串中的非字母字符都删除后的字符串。public (1) {public static String removeNonLetters( (2) ){StringBuffer aBuffer=(3);char aCharacter;for(int i=0; i<original.length();i++){aCharacter=(4);if(Character.isLetter(aCharacter))aBuffer.append( (5) );}return new String(aBuffer);}}public class StringEditorTester{public static void main(String args[]){String riginal="Hi!, My Name is Mark, 234I think you are my classmate?!!";System.out.println(StringEditor.removeNonLetters(original));}}

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include include 阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include < stdio. h >include < string. h >define Max 1000class Bank{int index;char date [Max] [10]; // 记录交易日iht amount[Max]; // 记录每次交易金额,以符号区分存钱和取钱int rest[ Max]; // 记录每次交易后余额static iht sum; // 账户累计余额public:Bank( ) {index =0;}void deposit( char d[ ] , int m) //存入交易{strcpy ( date [ index ], d);amount[ index] = m;(1);rest[ index] = sum;index++;}void withdraw (char d[ ], int m) //取出交易{strcpy( date[ index] ,d);(2);(3);rest[ index] = sum;index++;}void display( );};int Bank:: sum = 0;void Bank:: display ( ) //输出流水{int i;printf("日期 存入 取出 余额\n");for (4){printf(" %8s" ,date[i] );if (5)printf(" %6d" , -amount[i] );elseprintf( "%6d ",amount[i] );printf( "% 6d\n" ,rest[i] );} }void main( ){Bank object;object. deposit ( "2006.2.5", 1 00 );object. deposit( "2006.3.2" , 200);object. withdraw( "2006.4.1", 50);object. withdraw( "2006.4.5", 80);object. display ( );}本程序的执行结果如下:日期 存入 取出 余额 2006.2.5 100 1002006.3.2 200 3002006.4.1 50 2502006.4.5 80 170

阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。【说明】已知头指针分别为La和lb的有序单链表,其数据元素都是按值非递减排列。现要归并La和Lb得到单链表Lc,使得Lc中的元素按值非递减排列。程序流程图如下所示:

阅读以下说明及Visual Basic程序代码,将应填入(n)处的字句写在对应栏内。【说明】以下程序为求行列式X(5,5)的值S。【Visual Basic代码】Private Function col ( byval x ( 5,5 ) as integer ) as longdim fesult as longdim temp as longdim I as integerdim j as integerdim k as imegerresult = 0for I = to 5(1)for j = 1 to 5if I+j>6 thenk= ( 1+j ) mod 5elsek=1endiftemp=temp*x ( k,j )(2)result=(3)(4)(5)End function

阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。【说明】阅读下面几段C++程序回答相应问题。比较下面两段程序的优缺点。①for (i=0; i<N; i++ ){if (condition)//DoSomething…else//DoOtherthing…}②if (condition) {for (i =0; i<N; i++ )//DoSomething}else {for (i=0; i <N; i++ )//DoOtherthing…}

阅读下列程序说明和C程序,将应填入(n)处的字句写在对应栏内。[函数2.1说明]下面程序的功能是计算x和y的最小公倍数。[函数2.1]main(){ int m,n,d,r;seanf("%d %d",m,n);if(m<n) {r=m;m=n;n=r;}(1);while (d%n! =0) (2);printf("%d\n",d);}[函数2.2说明]下述程序接收键盘输入,直到句点“.”时结束。输入的字符被原样输出,但连续的空格输入将转换成一个空格。[函数2.2]include <stdio.h>main(){ char c,preChar='\0';c = getchar();while(c! = '.'){if((3)) putchar(c);else if(preChar! =' ') putchar(c);(4);c=(5);}}

●试题二阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】该程序运行后,输出下面的数字金字塔【程序】includestdio.hmain (){char max,next;int i;for(max=′1′;max=′9′;max++){for(i=1;i=20- (1) ;++i)printf(" ");for(next= (2) ;next= (3) ;next++)printf("%c",next);for(next= (4) ;next= (5) ;next--)printf("%c",next);printf("\n");}}

试题三(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。

()阅读下列说明和C语言程序,将应填入 (n)处的语句写在答题纸的对应栏内。[说明]下面程序是一个带参数的主函数,其功能是显示在命令行中输入的文本文件内容。[C语言函数]#include"stdio.h"main(argc,argv) int argc; char *argv[]; { (1) ; if((fp=fopen(argv[1],”r’’))== (2) ) { printf(”file not open!\n”);exit(0);} while( (3) ) putchar( (4) ); (5); }

阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。【说明】某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。