链表的综合操作源程序

链表的综合操作源程序

ID:38465354

大小:31.50 KB

页数:4页

时间:2019-06-13

链表的综合操作源程序_第1页
链表的综合操作源程序_第2页
链表的综合操作源程序_第3页
链表的综合操作源程序_第4页
资源描述:

《链表的综合操作源程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、#include#include#include#defineLENsizeof(structstudent)structstudent{intnum;floatscore;structstudent*next;};voidmain()//主函数{structstudent*creat(void);//建立一个动态链表structstudent*del(structstudent*head,intdel_num);//删除链表structstudent*insert(structstudent

2、*head,structstudent*stu);//插入链表voidprint(structstudent*head);//输出链表structstudent*head;structstudent*stu;//要插入的节点intdel_num;head=creat();//创建动态链表print(head);//输出原链表printf("");//空一格printf("Inputthedeletedel_num:");scanf("%d",&del_num);while(del_num!=0)//多次删除{head=del(head,del_n

3、um);printf("");printf("Thedeletedlistis:");print(head);printf("");printf("Inputthedeletedel_num:");scanf("%d",&del_num);}printf("");printf("Inputtheinsertnode:");stu=(structstudent*)malloc(LEN);scanf("%d,%f",&stu->num,&stu->score);while(stu->num!=0)//多次插入{head=insert(he

4、ad,stu);print(head);printf("");printf("Inputtheinsertnode:");stu=(structstudent*)malloc(LEN);scanf("%d,%f",&stu->num,&stu->score);}}/***************************************************//***************建立动态链表************************/structstudent*creat(void)//建立一个动态链表{intn;str

5、uctstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%d,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%d,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}/

6、***************************************************//***************删除链表***************************/structstudent*del(structstudent*head,intdel_num){structstudent*p1,*p2;if(head==NULL)printf("Thisisanulllist!");p1=head;while(del_num!=p1->num&&p1->num!=NULL){p2=p1;p1=p1->next;

7、}if(del_num==p1->num){if(p1==head)head=p1->next;elsep2->next=p1->next;printf("delete:%d",del_num);}elseprintf("%dnotbeenfound!",del_num);return(head);}/***************************************************//***************插入链表节点************************/structstudent*insert(st

8、ructstudent*head,structstudent*stu){structstudent*p0,*

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

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

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