二级考试辅导上机部分-part3_第1页
二级考试辅导上机部分-part3_第2页
二级考试辅导上机部分-part3_第3页
二级考试辅导上机部分-part3_第4页
二级考试辅导上机部分-part3_第5页
已阅读5页,还剩79页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

二级考试辅导上机部分,结构体、文件(最后一部分内容),第一部分:结构体,第一套,第三题,数组和结构体,#include#defineN8typedefstructcharnum10;doublesN;doubleave;STREC;voidfun(STREC*a)main()STRECs=GA005,85.5,76,69.5,85,91,72,64.5,87.5;inti;fun(,【参考答案】voidfun(STREC*a)STRECa-ave=0.0;inti;for(i=0;iave=a-ave+a-si;a-ave/=N;,第五套,第一题,结构体和指针,3,5,9,12,24,q,p,s,s-next=p,q-next=s,#include#include#defineN8typedefstructlistintdata;structlist*next;SLIST;voidfun(SLIST*h,intx)SLIST*p,*q,*s;s=(SLIST*)malloc(sizeof(SLIST);/*found*/s-data=_1_;q=h;p=h-next;while(p!=NULL,【参考答案】(1)x(2)p(3)s,SLIST*creatlist(int*a)SLIST*h,*p,*q;inti;h=p=(SLIST*)malloc(sizeof(SLIST);for(i=0;idata=ai;p-next=q;p=q;p-next=0;returnh;voidoutlist(SLIST*h)SLIST*p;p=h-next;if(p=NULL)printf(nThelistisNULL!n);elseprintf(nHead);doprintf(-%d,p-data);p=p-next;while(p!=NULL);printf(-Endn);,voidmain()SLIST*head;intx;intaN=11,12,15,18,19,22,25,29;head=creatlist(a);printf(nThelistbeforeinserting:n);outlist(head);printf(nEnteranumber:);scanf(%d,11套,第三题(结构体和文件),#include#include#defineN16typedefstructcharnum10;ints;STREC;STRECfun(STREC*a,char*b)voidmain()STRECsN=GA005,85,GA003,76,GA002,69,GA004,85,GA001,91,GA007,72,GA008,64,GA006,87,GA015,85,GA013,91,GA012,64,GA014,91,GA011,77,GA017,64,GA018,64,GA016,72;STRECh;charm10;inti;printf(Theoriginaldata:n);for(i=0;iN;i+)if(i%4=0)printf(n);printf(%s%3d,si.num,si.s);printf(nnEnterthenumber:);gets(m);h=fun(s,m);printf(Thedata:);printf(n%s%4dn,h.num,h.s);printf(n);h=fun(s,GA013);,16项下标0.15,【参考答案】STRECfun(STREC*a,char*b)inti;STRECstr=0,-1;for(i=0;iN;i+)if(strcmp(ai.num,b)=0)strai;str=ai;returnstr;,16套,第三题,【参考答案】intfun(STREC*a,STREC*b)inti,j=0,max=a0.s;/*找出最大值*/for(i=0;iN;i+)if(maxai.s)max=ai.s;for(i=0;iN;i+)if(max=ai.s)bj+=ai;returnj;,#include#defineN16typedefstructcharnum10;ints;STREC;intfun(STREC*a,STREC*b),main()STRECsN=GA05,85,GA03,76,GA02,69,GA04,85,GA01,91,GA07,72,GA08,64,GA06,87,GA015,85,GA013,91,GA012,64,GA014,91,GA011,77,GA017,64,GA018,64,GA016,72;STREChN;inti,n;FILE*out;n=fun(s,h);printf(The%dhighestscore:n,n);for(i=0;inext!=NULL)s=t;/*found*/t=t-_1_;/*found*/printf(%d,_2_);s-next=NULL;/*found*/free(_3_);SLIST*creatlist(int*a)SLIST*h,*p,*q;inti;h=p=(SLIST*)malloc(sizeof(SLIST);for(i=0;idata=ai;p-next=q;p=q;p-next=0;returnh;,voidoutlist(SLIST*h)SLIST*p;p=h-next;if(p=NULL)printf(nThelistisNULL!n);elseprintf(nHead);doprintf(-%d,p-data);p=p-next;while(p!=NULL);printf(-Endn);main()SLIST*head;intaN=11,12,15,18,19,22,25,29;head=creatlist(a);printf(nOutputfromhead:n);outlist(head);printf(nOutputfromtail:n);while(head-next!=NULL)fun(head);printf(nn);printf(nOutputfromheadagain:n);outlist(head);,(1)next,(2)t-data,(3)t,【考点分析】本题考查:链表数据结构,结点的表示方法,掌握链表数据结构的基本思想;释放内存空间函数free()。【解题思路】填空1:因为是链表操作,所以要使t逐一往后移动,语句为ttnext。填空2:输出链表结点的数据域,即tdata。填空3:使用free函数将t所指向的内存空间释放。释放内存空间函数free调用形式:free(void*p);。功能:释放p所指向的一块内存空间,p是一个任意类型的指针变量,它指向被释放区域的首地址。被释放区应是由malloc或calloc函数所分配的区域。,23套,第一题,NULL,3,3,4,5,5,h,#include#include#defineN8typedefstructlistintdata;structlist*next;SLIST;voidfun(SLIST*h)SLIST*p,*q;p=h-next;if(p!=NULL)q=p-next;while(q!=NULL)if(p-data=q-data)p-next=q-next;/*found*/free(_1_);/*found*/q=p-_2_;elsep=q;/*found*/q=q-_3_;,SLIST*creatlist(int*a)SLIST*h,*p,*q;inti;h=p=(SLIST*)malloc(sizeof(SLIST);for(i=0;idata=ai;p-next=q;p=q;p-next=0;returnh;voidoutlist(SLIST*h)SLIST*p;p=h-next;if(p=NULL)printf(nThelistisNULL!n);elseprintf(nHead);doprintf(-%d,p-data);p=p-next;while(p!=NULL);printf(-Endn);main()SLIST*head;intaN=1,2,2,3,4,4,4,5;head=creatlist(a);printf(nThelistbeforedeleting:n);outlist(head);fun(head);printf(nThelistafterdeleting:n);outlist(head);,(1)q,(2)next,(3)next,31套,第一题,NULL,2,4,6,8,10,h,p,2,#include#include#defineN5typedefstructnodeintdata;structnode*next;NODE;voidfun(NODE*h)NODE*p,*q,*r;/*found*/p=h-_1_;/*found*/if(p=_2_)return;q=p-next;p-next=NULL;while(q)r=q-next;q-next=p;/*found*/p=q;q=_3_;h-next=p;,NODE*creatlist(inta)NODE*h,*p,*q;inti;h=(NODE*)malloc(sizeof(NODE);h-next=NULL;for(i=0;idata=ai;q-next=NULL;if(h-next=NULL)h-next=p=q;elsep-next=q;p=q;returnh;,【参考答案】(1)next(2)NULL(3)r,voidoutlist(NODE*h)NODE*p;p=h-next;if(p=NULL)printf(ThelistisNULL!n);elseprintf(nHead);doprintf(-%d,p-data);p=p-next;while(p!=NULL);printf(-Endn);main()NODE*head;intaN=2,4,6,8,10;head=creatlist(a);printf(nTheoriginallist:n);outlist(head);fun(head);printf(nThelistafterinverting:n);outlist(head);,【解题思路】填空1:本空考查了为p赋初值,根据题目的要求是将带头结点的单向链表逆置可知,p的初值应该为h-next。填空2:if判断语句表明当p等于什么时就要返回,因此只能当p等于NULL时返回,不用做后面的链表的逆置了。填空3:把q的指针向后移动,才能实现将带头结点的单向链表逆置。因此本空填写r。,33套,第一题,NULL,10,4,2,8,6,h,p,q,#include#include#defineN6typedefstructnodeintdata;structnode*next;NODE;voidfun(NODE*h)NODE*p,*q;intt;p=h;while(p)/*found*/q=_1_;/*found*/while(_2_)if(p-dataq-data)t=p-data;p-data=q-data;q-data=t;q=q-next;/*found*/p=_3_;NODE*creatlist(inta)NODE*h,*p,*q;inti;h=NULL;for(i=0;idata=ai;q-next=NULL;if(h=NULL)h=p=q;elsep-next=q;p=q;returnh;,voidoutlist(NODE*h)NODE*p;p=h;if(p=NULL)printf(ThelistisNULL!n);elseprintf(nHead);doprintf(-%d,p-data);p=p-next;while(p!=NULL);printf(-Endn);main()NODE*head;intaN=0,10,4,2,8,6;head=creatlist(a);printf(nTheoriginallist:n);outlist(head);fun(head);printf(nThelistafterinverting:n);outlist(head);,(3)p-next,(1)p-next,(2)q,83套,第三题,#include#defineN50#defineM11voidfun(int*a,int*b)doublernd()statict=29,c=217,m=1024,r=0;r=(r*t+c)%m;return(double)r/m);,【参考答案】voidfun(int*a,int*b)inti,j;for(j=0;j=100)b10+;elsebai/10+;,voidmain()intageN,i,dM;intbN=32,45,15,12,86,49,97,3,44,52,17,95,63;for(i=0;iN;i+)agei=(int)(115*rnd();printf(Theoriginaldata:n);for(i=0;iN;i+)printf(i+1)%10=0?%4dn:%4d,agei);printf(nn);fun(age,d);for(i=0;i10;i+)printf(%4d-%4d:%4dn,i*10,i*10+9,di);printf(Over100:%4dn,d10);,第二部分:文件,12套,第一套,#include#includeintfun(char*source,char*target)FILE*fs,*ft;charch;/*found*/if(fs=fopen(source,_1_)=NULL)return0;if(ft=fopen(target,w)=NULL)return0;printf(nThedatainfile:n);ch=fgetc(fs);/*found*/while(!feof(_2_)putchar(ch);/*found*/fputc(ch,_3_);ch=fgetc(fs);fclose(fs);fclose(ft);printf(nn);return1;,main()charsfname20=myfile1,tfname20=myfile2;FILE*myf;inti;charc;myf=fopen(sfname,w);printf(nTheoriginaldata:n);for(i=1;i30;i+)c=A+rand()%25;fprintf(myf,%c,c);printf(%c,c);fclose(myf);printf(nn);if(fun(sfname,tfname)printf(Succeed!);elseprintf(Fail!);,【参考答案】(1)r(2)fs(3)ft,【考点分析】本题考查:打开文件操作,fopen函数用来打开一个文件,其一般形式为文件指针名fopen(文件名,使用文件方式);文件结束检测函数feof函数;写字符函数fputc,功能是把一个字符写入指定的文件中,函数调用的形式为fputc(字符量,文件指针);其中,待写入的字符量可以是字符常量或变量,被写入的文件可以用写、读写、追加方式打开。文件一旦使用完毕,需使用关闭文件函数fclose将文件关闭,以避免文件的数据丢失等错误。【解题思路】填空1:本题考查对文件操作的掌握。打开一个文件的调用方式是,fsfopen(文件名,使用文件方式),以只读的方式打开文件,所以文件使用方式为r。填空2:while循环语句中,循环条件通过feof()函数来检测是否到文件结尾。填空3:fputc()函数用于将一个字符写到磁盘文件上去,调用形式为:fputc(要输出的字符,文件指针)。,15套,第一题,#include#include#includevoidWriteText(FILE*);voidReadText(FILE*);main()FILE*fp;if(fp=fopen(myfile4.txt,w)=NULL)printf(openfail!n);exit(0);WriteText(fp);fclose(fp);if(fp=fopen(myfile4.txt,r)=NULL)printf(openfail!n);exit(0);ReadText(fp);fclose(fp);/*found*/voidWriteText(FILE_1_)charstr81;printf(nEnterstringwith-1toend:n);gets(str);while(strcmp(str,-1)!=0)/*found*/fputs(_2_,fw);fputs(n,fw);gets(str);,voidReadText(FILE*fr)charstr81;printf(nReadfileandoutputtoscreen:n);fgets(str,81,fr);while(!feof(fr)/*found*/printf(%s,_3_);fgets(str,81,fr);,【参考答案】(1)*fw(2)str(3)str,25套,第一题,#include#defineN5typedefstructstudentlongsno;charname10;floatscore3;STU;voidfun(char*filename,longsno)FILE*fp;STUn;inti;fp=fopen(filename,rb+);/*found*/while(!feof(_1_)fread(,【参考答案】(1)fp(2)=(3)fp,main()STUtN=10001,MaChao,91,92,77,10002,CaoKai,75,60,88,10003,LiSi,85,70,78,10004,FangFang,90,82,87,10005,ZhangSan,95,80,88,ssN;inti,j;FILE*fp;fp=fopen(student.dat,wb);fwrite(t,sizeof(STU),N,fp);fclose(fp);printf(nTheoriginaldata:n);fp=fopen(student.dat,rb);fread(ss,sizeof(STU),N,fp);fclose(fp);for(j=0;jN;j+)printf(nNo:%ldName:%-8sScores:,ssj.sno,);for(i=0;i3;i+)printf(%6.2f,ssj.scorei);printf(n);fun(student.dat,10003);fp=fopen(student.dat,rb);fread(ss,sizeof(STU),N,fp);fclose(fp);printf(nThedataaftermodifing:n);for(j=0;jN;j+)printf(nNo:%ldName:%-8sScores:,ssj.sno,);for(i=0;i3;i+)printf(%6.2f,ssj.scorei);printf(n);,71套,第一题,知识点:文件和结构体,#include#include#include#includevoidfun(char*s,chart)voidmain()chars100,t100;system(CLS);printf(nPleaseenterstringS:);scanf(%s,s);fun(s,t);printf(nTheresultis:%sn,t);,【参考答案】(1)filename(2)fp(3)fp【解题思路】填空1:本空是对文本文件的打开,filename所指的文件中的最后数据要进行重写,因此首先是要打开,因而本空填写filename。填空2:fseek功能是重定位流上的文件指针。用法:intfseek(FILE*stream,longoffset,intfromwhere);本空应该填写fp。填空3:因为题目中要对所有学生数据均以二进制方式输出到文件中,因此本空填写fp。知识点讲解:函数名:fseek功能:重定位流上的文件指针。用法:intfseek(FILE*stream,longoffset,intfromwhere)。描述:函数设置文件指针stream的位置。如果执行成功,stream将指向以fromwhere为基准,偏移offset个字节的位置。如果执行失败(比如offset超过文件自身大小),则不改变stream指向的位置。返回值:成功,返回0;否则返回非0值。,第三部分:自测题,自测题:80套,第一题,#include#defineN5typedefstructstudentlongsno;charname10;floatscore3;STU;voidfun(char*filename)FILE*fp;inti,j;STUsN,t;/*found*/fp=fopen(filename,_1_);fread(s,sizeof(STU),N,fp);fclose(fp);for(i=0;iN-1;i+)for(j=i+1;jN;j+)/*found*/if(si.sno_2_sj.sno)t=si;si=sj;sj=t;fp=fopen(filename,wb);/*found*/_3_(s,sizeof(STU),N,fp);fclose(fp);,main()STUtN=10005,ZhangSan,95,80,88,10003,LiSi,85,70,78,10002,CaoKai,75,60,88,10004,FangFang,90,82,87,10001,MaChao,91,92,77,ssN;inti,j;FILE*fp;fp=fopen(student.dat,wb);fwrite(t,sizeof(STU),5,fp);fclose(fp);printf(nnTheoriginaldata:nn);for(j=0;jN;j+)printf(nNo:%ldName:%-8sScores:,tj.sno,);for(i=0;i3;i+)printf(%6.2f,tj.scorei);printf(n);fun(student.dat);printf(nnThedataaftersorting:nn);fp=fopen(student.dat,rb);fread(ss,sizeof(STU),5,fp);fclose(fp);for(j=0;j。填空3:题目要求所有的学生数据均以二进制方式输出到文件中,因此本空填写fwrite。,自测题:14套,第一题,#include#includestructstudentlongsno;charname10;floatscore3;voidfun(structstudenta)structstudentb;inti;/*found*/b=_1_;b.sno=10002;/*found*/strcpy(_2_,LiSi);printf(nThedataaftermodified:n);printf(nNo:%ldName:%snScores:,b.sno,);/*found*/for(i=0;i3;i+)printf(%6.2f,b._3_);printf(n);,main()structstudents=10001,ZhangSan,95,80,88;inti;printf(nnTheoriginaldata:n);printf(nNo:%ldName:%snScores:,s.sno,);for(i=0;i3;i+)printf(%6.2f,s.scorei);printf(n);fun(s);,【参考答案】(1)a(2)(3)scorei【考点分析】本题考查:结构体数据类型;strcpy字符串拷贝函数。【解题思路】填空1:题目要求先将形参a所指结构体变量中的数据赋给函数中的结构体变量b,所以此处ba。填空2:通过strcpy函数修改b中的学生姓名,注意结构变量成员的表示方法。填空3:printf函数输出结果。【解题宝典】结构变量成员的一般形式是:结构变量名成员名例如:student1.num即第一个学生的学号student2.sex即第二个学生的性别,自测题,22套,第一题,#include#includestructstudentlongsno;charname10;floatscore3;voidfun(structstudent*b)/*found*/b_1_=10004;/*found*/strcpy(b_2_,LiJie);,main()structstudentt=10002,ZhangQi,93,85,87;inti;printf(nnTheoriginaldata:n);printf(nNo:%ldName:%snScores:,t.sno,);for(i=0;iname(3)doubles;STREC;doublefun(STREC*a,STREC*b,int*n),main()STRECsN=GA05,85,GA03,76,GA02,69,GA04,85,GA01,91,GA07,72,GA08,64,GA06,87,GA09,60,GA11,79,GA12,73,GA10,90;STREChN,t;FILE*out;inti,j,n;doubleave;ave=fun(s,h,【参考答案】doublefun(STREC*a,STREC*b,int*n)inti;doubleav=0.0;*n=0;for(i=0;iN;i+)av=av+ai.s;av=av/N;/*求平均值*/for(i=0;inext=q;p=q;p-next=0;returnh;,outlist(STREC*h)STREC*p;p=h-next;printf(head);doprintf(-%2.0f,p-s);p=p-next;while(p!=0);printf(nn);main()doublesN=85,76,69,85,91,72,64,87,max;STREC*h;h=creat(s);outlist(h);max=fun(h);printf(max=%6.1fn,max);,【参考答案】doublefun(STREC*h)doublemax=h-s;while(h!=NULL)/*通过循环找到最高分数*/if(maxs)max=h-s;h=h-next;returnmax;【考点分析】本题考查:结构体类型;指针型变量;链表的相关知识。【解题思路】本题使用循环语句遍历链表中的每个结点,用判断语句比较结点数据的域大小。注意,h是一个指向结构体类型的指针变量,若要引用它所指向的结构体中的某一成员时,要用指向运算符。,自测题:28套,第一题,#include#include#defineN8typedefstructlistintdata;structlist*next;SLIST;SLIST*creatlist(int*);voidoutlist(SLIST*);intfun(SLIST*h)SLIST*p;ints=0;p=h-next;while(p)/*found*/s+=p-_1_;/*found*/p=p-_2_;returns;main()SLIST*head;intaN=12,87,45,32,91,16,20,48;head=creatlist(a);outlist(head);/*found*/printf(nsum=%dn,fun(_3_);,SLIST*creatlist(inta)SLIST*h,*p,*q;inti;h=p=(SLIST*)malloc(sizeof(SLIST);for(i=0;idata=ai;p-next=q;p=q;p-next=0;returnh;voidoutlist(SLIST*h)SLIST*p;p=h-next;if(p=NULL)printf(ThelistisNULL!n);elseprintf(nHead);doprintf(-%d,p-data);p=p-next;while(p!=NULL);printf(-Endn);,【参考答案】(1)data(2)next(3)head【考点分析】本题考查:链表数据结构,结点的表示方法;掌握链表数据结构的基本思想。【解题思路】本题考查的是链表的数据结构,需利用指针变量才能实现,一个结点中应包含一个指针变量,用来存放下一个结点的地址。建立单项链表的一般步骤是:建立头指针建立第一个结点头指针指向第一个结点建立第二个结点第一个结点的指针与指向第二个结点最后一个结点的指针指向NULL。填空1:变量s用来累加各结点的数据域,因此该空应为data。填空2:每次循环结束时,指针P指向下一个结点,即ppnext。填空3:由被调用函数的形参列表可知,此处应为指针类型变量,因为要对链表的数据域求和,所以在将链表的头指针传给被调用函数。,自测题,29套,第一题,#include#includestructstudentlongsno;charname10;floatscore3;/*found*/_1_fun(structstudent*a)inti;a-sno=10002;strcpy(a-name,LiSi);/*found*/for(i=0;iname);for(i=0;iscorei);printf(n);,【参考答案】(1)structstudent*(2)a-scorei(3)a【考点分析】本题考查:函数定义;结构变量成员函数的表示方法;函数返回值。【解题思路】填空1:函数定义时,类型标识符指明了本函数的类型,我们前面已经多次提到,函数的类型实际上是函数返回值的类型。该题中,用结构指针变量作为函数类型标识符。填空2:通过循环语句对指针a所指结构体变量中的3门成绩进行修改,所以此处为ascorei。填空3:通过return语句将形参a返回给主调函数。【解题宝典】结构变量各个成员的表示方法:(*结构指针变量)成员名;或:结构指针变量成员名,自测题:40套,第一题,#include#includestructstudentlongsno;charname10;floatscore3;/*found*/_1_fun(structstudenta)inti;a.sno=10002;/*found*/strcpy(_2_,LiSi);/*found*/for(i=0;i3;i+)_3_+=1;returna;,main()structstudents=10001,ZhangSan,95,80,88,t;inti;printf(nnTheoriginaldata:n);printf(nNo:%ldName:%snScores:,s.sno,);for(i=0;is;p=p-next;returnave/N;【考点分析】本题考查:链表的操作,对链表的主要操作有以下几种:建立链表、结构的查找与输出、插入一个结点、删除一个结点。【解题思路】题目要求求链表中数据域的平均值,应首先使用循环语句遍历链表,求各结点数据域中数值的和,再对和求平均分。遍历链表时应定义一个指向结点的指针p,因为头结点中没有数值,所以程序中让p直接指向头结点的下一个结点,使用语句STREC*phnext。,自测题:39套,第一题,#include#include#defineN5typedefstructnodeintdata;structnode*next;NODE;/*found*/_1_*fun(NODE*h)NODE*p,*q,*r;p=h;if(p=NULL)returnNULL;q=p-next;p-next=NULL;while(q)/*found*/r=q-_2_;q-next=p;p=q;/*found*/q=_3_;returnp;,NODE*creatlist(inta)NODE*h,*p,*q;inti;h=NULL;for(i=0;idata=ai;q-next=NULL;if(h=NULL)h=p=q;elsep-next=q;p=q;returnh;voidoutlist(NODE*h)NODE*p;p=h;if(p=NULL)printf(ThelistisNULL!n);elseprintf(nHead);doprintf(-%d,p-data);p=p-next;while(p!=NULL);printf(-Endn);main()NODE*head;intaN=2,4,6,8,10;head=creatlist(a);printf(nTheoriginallist:n);outlist(head);head=fun(head);printf(nThelistafterinverting:n);outlist(head);,【参考答案】(1)NODE(2)next(3)r【解题思路】填空1:本题考查了函数指针变量的函数返回值的类型,*fun(NODE*h)的返回值为p,而p的数据类型为NODE,因此本空应该填写NODE。填空2:从此空的形式p-可知本空应该填写next。填空3:本题要求将不带头结点的单向链表逆置,为了使q的指针向后移,此空应该填写r。,自测题:72套,第三题,#include#include#include#include#defineN10typedefstructsscharnum10;ints;STU;fun(STUa,STU*s),voidmain()STUaN=A01,81,A02,89,A03,66,A04,87,A05,77,A06,90,A07,79,A08,61,A09,80,A10,71,m;inti;system(CLS);printf(*Theoriginaldata*n);for(i=0;iai.s)/*将当前值保存到s中*/*s=ai;【解题思路】找出结构体数组元素中的最小值。先认为第1个值最小,即*sa0;,如果在循环的过程中发现比第1个值更小的,就将指针s指向该元素,直到找到最小元素。另外,本题还涉及结构体中的指向运算符,请考生注意。,自测题:77套,第二题,#include#include#includetypedefstructaaintdata;structaa*next;NODE;NODE*Creatlink(intn,intm)NODE*h=NULL,*p,*s;inti;s=(NODE*)malloc(sizeof(NODE);h=s;/*found*/p-next=NULL;for(i=1;idata=rand()%m;s-next=p-next;p-next=s;p=p-next;s-next=NULL;/*found*/returnp;,outlink(NODE*h)NODE*p;p=h-next;printf(nTheLIST:nnHEAD);while(p)printf(-%d,p-data);p=p-next;printf(n);,【参考答案】(1)p=s;(2)s-data=rand()%(m-1);(3)returnh;【解题思路】(1)进行循环操作前应初始化指针p,使其指向链表s。(2)因为结点数据域的取值范围为0m1,所以此处应改为sdatarand()%(m1);。(3)最后要将链表的头指针返回给主函数。,自测题:81套,第二题,#include#include#includetypedefstructaaintdata;structaa*next;NODE;intfun(NODE*h)intsum=0;NODE*p;p

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论