建立和删除动态链表.doc

建立和删除动态链表.doc

ID:58460979

大小:16.50 KB

页数:2页

时间:2020-09-03

建立和删除动态链表.doc_第1页
建立和删除动态链表.doc_第2页
资源描述:

《建立和删除动态链表.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、#include#include#include#defineLENsizeof(structstudent)structstudent*creat();structstudent*del(structstudent*head,intnum);voidprint(structstudent*head);###########################################structstudent{intnum;floatscore;

2、structstudent*next;};intn;###########################################voidmain(){structstudent*stu,*p;intn;stu=creat();p=stu;print(p);printf("pleaseenterthenumtodelete:");scanf("%d",&n);print(del(p,n));}###########################################structstu

3、dent*creat(){structstudent*head;structstudent*p1,*p2;p1=p2=(structstudent*)malloc(LEN);printf("pleaseenterthenum:");scanf("%d",&p1->num);printf("pleaseenterthescore:");scanf("%f",&p1->score);head=NULL;n=0;while(p1->num){n++;if(1==n){head=p1;}else{p2->next=

4、p1;}p2=p1;p1=(structstudent*)malloc(LEN);printf("pleaseenterthenum:");scanf("%d",&p1->num);printf("pleaseenterthescore:");scanf("%f",&p1->score);}p2->next=NULL;returnhead;}###########################################voidprint(structstudent*head){structstu

5、dent*p;printf("thereare%dreconds!",n);if(head){p=head;do{printf("学号%d的成绩为:%f",p->num,p->score);p=p->next;}while(p);}}structstudent*del(structstudent*head,intnum){structstudent*p1,*p2;if(NULL==head){printf("thislistisnull");gotoEND;}p1=head;while(

6、p1->num!=num&&p1->next!=NULL){p2=p1;p1=p1->next;}if(num==p1->num){if(p1==head){head=p1->next;}else{p2->next=p1->next;}printf("deleteNo.%dsucceed!",num);n=n-1;}else{printf("%dnotbeenfound!",num);}END:returnhead;}

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

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

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