2016广工Anyview试题答案 第十一章.doc_第1页
2016广工Anyview试题答案 第十一章.doc_第2页
2016广工Anyview试题答案 第十一章.doc_第3页
2016广工Anyview试题答案 第十一章.doc_第4页
2016广工Anyview试题答案 第十一章.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

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

文档简介

/* 11.023 数组s存储了n个人的信息。写一函数,求这n个人中年龄最大(即出生日期最小者的姓名。 */char *oldest(student s, int n) int j,k=0; for(j=1;jsj.birth.year) k=j; else if(sk.birth.year=sj.birth.year) if(sk.birth.monthsj.birth.month) k=j; else if(sk.birth.month=sj.birth.month) if(sk.birth.daysj.birth.day) k=j; return ;/* 11.033 链表L存储了多个人的信息。写一函数,求这些人中年龄最大 (即出生日期最小)者的名字。 结构体类型定义如下: struct dateint year; int month; int day; /日期结构体类型 struct studentNode /链表结点的结构体类型 char name10; /人名 struct date birth; /出生日期 struct studentNode *next ; */char *oldest(struct studentNode *L)/* 若L是空表,则返回空指针null 否则返回表中年龄最大者的名字 */ struct studentNode *p; if(L=NULL) return NULL; for(p=L-next;p!=NULL;p=p-next) if(*p).birth.year(*L).birth.year) continue; if(*p).birth.year=(*L).birth.year) if(*p).birth.month(*L).birth.month) continue; if(*p).birth.month=(*L).birth.month&(*p).birth.day=(*L).birth.day) continue; L=p; return(*L).name);/* 11.063 结构体类型定义如下: struct course int cID; /课程号,取值099 char name10; /课程名 float credit; /学分,取值05 int semester; /学期,取值18 ; 结构体数组c存储了n门课程的信息。写一函数,求学期s的总学分。 */float creditSum(struct course c, int n, int s) int i; float sum=0.0; for(i=0;inext;p!=NULL;p=p-next) if(*p).semester=s) sum+=(*p).credit; if(s=1)sum+=(*Lc).credit; return sum; /* 11.133 日期和结构体类型定义如下: struct dateint year; int month; int day; /日期结构体类型 struct student /结构体类型 char name10; /人名 struct date birth; /出生日期 ; 结构体数组s存储了n个人的名字和出生日期。写一函数,由数组s中n个人 的信息及其顺序构造相应的链表。链表的结点的结构体类型定义如下: struct studentNode /结构体类型 char name10; /人名 struct date birth; /出生日期 struct studentNode *next ; */#define N sizeof(struct studentNode)struct studentNode *CreateLinkList(struct student s, int n) struct studentNode *head,*p1,*p2;int i=0; p1=p2=(struct studentNode *) malloc(N); head=NULL; while(iname,); p1-birth=si.birth; if(i=0) head=p1; else p2-next=p1; p2=p1; p1=(struct studentNode *) malloc(N); +i; p2-next=NULL; return (head);/* 11.173 课程链表结点的结构体类型定义如下: struct courseNode /课程链表结点的结构体类型 int cID; /课程号,取值099 char name10; /课程名 float credit; /学分,取值05 int semester; /学期,取值18 struct courseNode *next; ; 结构体链表Lc存储了多门课程的信息。写一函数,将课程号 为c的课程的学分修改为t。 */struct courseNode *creditChange(struct courseNode *Lc, int c, float t)/* 若课程c不存在,则修改不成功,返回null; 否则修改该课程的学分为t,返回指向该课程结点的指针。 */ struct courseNode *Lc2; while(Lc!=NULL) if(Lc-cID=c) Lc-credit=t,Lc2=Lc; Lc=Lc-next; return(Lc2);/11.183 课程链表结点的结构体类型定义如下:/ struct courseNode /课程链表结点的结构体类型/ int cID; /课程号,取值099/ char name10; /课程名/ float credit; /学分,取值05/ int semester; /学期,取值18/ struct courseNode *next;/ ;/结构体链表Lc存储了多门课程的信息。写一函数,将课程号为c的课程结点删除。/要求实现下列函数:struct courseNode *deleteCourse(struct courseNode *Lc, int c)/* 若在链表Lc中课程c不存在,则删除不成功,返回null; 否则从链表Lc中删除该课程结点,并返回指向该课程结点的指针。 */ struct courseNode *p,*q,*t; p=*Lc; while(c!=p-cID&p-next!=NULL) q=p; p=p-next; if(c=p-cID) if(p=*Lc) t=p; *Lc=p-next; else t=p; q-next=p-next; return(t);/*11.302 单向链表的结点类型定义如下: struct node char ch; struct node *next; ;编写函数,对单向链表L实现就地逆置,即将所有结点的指针反向,原链头当作链尾,原链尾当作链头,并返回逆置后链表的头指针。*/struct node *inverse(struct node *L) struct node *p=L,*q;int n=0,i=0; char t; while(p!=NULL) p=p-next; +n; p=L; for(;inext; if(p-ch)ch) t=p-ch,p-ch=q-ch,q-ch=t; if(q-next!=NULL) p=p-next; else p=NULL; p=L; return L;/*11.352 单向链表的结点类型定义如下: struct node char ch; struct node *next; ;编写函数,对单向链表L实现排序,即按结点的ch值,从小到大重构链表L,并返回排序后的链表的头指针。*/struct node *sorting(struct node *L)/* 对单向链表L实现从小到大排序, 并返回重构后的链表的头指针。 */ struct

温馨提示

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

评论

0/150

提交评论