- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
(2) void free(void *ptr) 功能:释放由malloc()申请的动态内存空间,ptr存放该空间的首地址。 返回值:无。 p=(struct student *) malloc(sizeof(struct student)); …… free(p); 第二十九页,共46页。 2、建立链表 编写一个函数,要求用单向链表建立学生档案,从键盘输入数据,如果学号为0,输入结束,并返回链表的头指针。 struct student { long int num; float score; struct student *next; }; struct student *head, *tail, *p; head=tail=NULL; 第三十页,共46页。 struct student *head, *tail, *p; head=tail=NULL; size=sizeof(struct student); p = (struct student *) malloc(size); p num score next head tail p tail 第三十一页,共46页。 head=tail=NULL; input num, score while num!=0 p= (struct student *) malloc(sizeof(size)) p-num=num, p-score=score, p-next=NULL y head==NULL n head=p tail-next=p tail=p input num, score 第三十二页,共46页。 # include stdio.h struct student { int num; float score; struct student *next; }; struct student *creat( ); main( ) { struct student *head; head = creat( ); } 第三十三页,共46页。 struct student *creat() { struct student *head, *tail, *p; float score; int num, size = sizeof(struct student); head = tail = NULL; scanf(%d %f, num, score); while (num){ p = (struct student *)malloc(size); p-num = num; p-score = score; p-next = NULL; if(head == NULL) head = p; else tail-next = p; tail = p; scanf(%d %f, num, score); } return head; } 第三十四页,共46页。 3、遍历链表 ptr-num ptr-score head 9901 80 9902 90 9903 75 NULL ptr ptr for(ptr=head; ptr!=NULL; ptr=ptr-next) printf(“%ld, %f”, ptr-num, ptr-score); ptr=ptr-next 第三十五页,共46页。 # include stdio.h struct student { int num; float score; struct student *next; }; struct student *creat( ); void print(struct student *head) main( ) { struct student *head; head = creat(); print(head); } 第三十六页,共46页。 void print(struct student *head) { struct student *ptr; if(head == NULL){ printf(\n No list\n); retur
您可能关注的文档
最近下载
- 华东师大版八年级数学上册《作一个角等于已知角》教案及教学反思.docx VIP
- 【真题】河南省2025年对口升学(语文、英语)考试真题卷 完整版2025.pdf VIP
- 中心吸氧装置出现故障的应急预案.pptx VIP
- 13.4.2作一个角等于已知角展示课件数学八年级上册.pptx VIP
- 梦幻西游手游科举乡试会试答案大全 乡试答题器.pdf VIP
- QB∕T 5617-2021 单层床通用技术条件 .pdf
- 设备采购与管理作业指导书(设备采购类).doc VIP
- 2022 ASHRAE Handbook Refrigeration. SI edition标准原版完整.docx
- 教职工请假单(部门存根)(模板).pdf VIP
- 学校篮球比赛报名表的表格打印模板文档.xlsx VIP
文档评论(0)