C语言链表实现学生成绩信息的管理.doc

C语言链表实现学生成绩信息的管理.doc

ID:52564103

大小:29.50 KB

页数:8页

时间:2020-03-28

C语言链表实现学生成绩信息的管理.doc_第1页
C语言链表实现学生成绩信息的管理.doc_第2页
C语言链表实现学生成绩信息的管理.doc_第3页
C语言链表实现学生成绩信息的管理.doc_第4页
C语言链表实现学生成绩信息的管理.doc_第5页
资源描述:

《C语言链表实现学生成绩信息的管理.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、/*----------------------------------------------//Student.cpp:链表实现对学生成绩的管理------------------------------------------------*/#include#include#includeusingnamespacestd;structStudent{intid;char*name;floatscore;Student*next;};Student*Create();Student*Create(inti,char*ch,floa

2、tsc);voidInsert(Student*h,Student*p);voidOutput(Student*h);Student*Search(Student*h,constintid);voidDelete(Student*h,Student*p);intmain(intargc,char*argv[]){Student*head,*p;head=Create();p=Create(1,"a",83);Insert(head,p);p=Create(2,"b",97);Insert(head,p);p=Create(3,"c",64);Insert(head,p);p=Create(4,

3、"d",76);Insert(head,p);p=Create(5,"e",83);Insert(head,p);Output(head);p=Search(head,2);Delete(head,p);Output(head);return0;}Student*Create(){Student*head;head=(Student*)malloc(sizeof(Student));head->next=NULL;returnhead;}Student*Create(inti,char*ch,floatsc){Student*p;p=(Student*)malloc(sizeof(Studen

4、t));p->id=i;p->name=ch;p->score=sc;p->next=NULL;returnp;}voidInsert(Student*h,Student*p){/*Student*cur;cur=h;while(cur->next!=NULL){cur=cur->next;}cur->next=p;*/if(h->next==NULL){h->next=p;}else{Student*cur,*q;for(q=h->next;q!=NULL;q=q->next){if(q->id>p->id)break;}for(cur=h;cur->next!=q;cur=cur->nex

5、t);if(q==NULL){cur->next=p;}else{p->next=q;cur->next=p;}}}voidOutput(Student*h){if(h->next==NULL){cout<<"链表为空!"<next;while(cur!=NULL){cout<<"t"<id<<"t"<name<<"t"<score<next;}}}Stude

6、nt*Search(Student*h,constintid){if(h->next==NULL){cout<<"链表为空,不能查找!"<next;while(cur!=NULL){if(id==cur->id)break;cur=cur->next;}if(cur==NULL){cout<<"没有找到!"<next==NULL){cout<<"链表为空,不能删除!"<

7、dent*cur;cur=h->next;while(cur->next!=p){cur=cur->next;}cur->next=p->next;p=NULL;free(p);}}

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。