资源描述:
《C语言链表实验题.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、等级考试1.学生的记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组s中,请编写函数fun,其功能是:按分数降序排列学生的记录,高分在前,低分在后。#include#defineN16typedefstruct{charnum[10];ints;}STREC;voidfun(STRECa[]){}main(){STRECs[N]={{"GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},{"GA001",91},{"GA007",72},{"GA008",64},{"
2、GA006",87},{"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91},{"GA011",66},{"GA017",64},{"GA018",64},{"GA016",72}};inti;FILE*out;fun(s);printf("Thedataaftersorted:");for(i=0;i3、","w");for(i=0;i#include#defineN8typedefstructlist{intdata;structlist*n
4、ext;}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;inta[N]={12,87,45,32,91,16,20,48};head=creatlist(a);outlist(hea
5、d);/**********found**********/printf("sum=%d",fun(___3___));}SLIST*creatlist(inta[]){SLIST*h,*p,*q;inti;h=p=(SLIST*)malloc(sizeof(SLIST));for(i=0;idata=a[i];p->next=q;p=q;}p->next=0;returnh;}voidoutlist(SLIST*h){SLIST*p;p=h->nex
6、t;if(p==NULL)printf("ThelistisNULL!");else{printf("Head");do{printf("->%d",p->data);p=p->next;}while(p!=NULL);printf("->End");}}3.学生的记录由学号成绩组成,N名学生的数据已放入主函数中的结构体数组s中,请编写函数fun,其功能是:函数返回该学号的学生数据,指定的学号在主函数中输入。若没有找到指定的学号,在结构体变量中给学号置空串,给成绩置-1,作为函数值返回。#include#inclu
7、de#defineN16typedefstruct{charnum[10];ints;}STREC;STRECfun(STREC*a,char*b){}main(){STRECs[N]={{"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},{"
8、GA017",64},{"GA018",64},{"GA016",72}};STRECh;charm[10];inti;FILE*out;printf