实验二 链表的实现和应用

实验二 链表的实现和应用

ID:4161848

大小:42.50 KB

页数:7页

时间:2017-11-29

实验二 链表的实现和应用_第1页
实验二 链表的实现和应用_第2页
实验二 链表的实现和应用_第3页
实验二 链表的实现和应用_第4页
实验二 链表的实现和应用_第5页
资源描述:

《实验二 链表的实现和应用》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、实验二链表的实现和应用一、实验目的掌握线性表的链式存储结构设计与基本操作的实现二、实验内容与要求⑴定义线性表的链式存储表示;⑵基于所设计的存储结构实现线性表的基本操作;⑶编写一个主程序对所实现的线性表进行测试;⑷线性表的应用:①设线性表L1和L2分别代表集合A和B,试设计算法求A和B的并集C,并用线性表L3代表集合C;②设线性表L1和L2中的数据元素为整数,且均已按值非递减有序排列,试设计算法对L1和L2进行合并,用线性表L3保存合并结果,要求L3中的数据元素也按值非递减有序排列。三、数据结构设计在主函数中实现函数的调用,从而实现线性表的插入、删除、创建、显示等。四、测

2、试结果通过输入不同的数字(1~6)实现不同的操作,在两个线性表结合时,线性表二在源程序中已给出的,通过操作可以得到非单调递减的有序数列五、心得体会在写程序的过程中要注意分析,参照其他标准程序,多上机运行一点点的改正错误,这样才会有所提高。MAIN.C方丽平信计1203班1130112321最后修改时间2014/3/31#include#include#definemaxsize1024typedefintdatatype;typedefstructnode{datatypedata;structnode*next;}linkList

3、;intmain(){linkList*CREATE();intINSERT(linkList*head,intvalue,intposition);intDELETE(linkList*head,intposition);intDISPLAY(linkList*head);linkList*COMBINE(linkList*head1,linkList*head2);linkList*head1;linkList*head2;linkList*head3;linkList*head;linkList*p1,*p2,*s1,*s2,*r1,*r2;intposition

4、,value,i;head1=malloc(sizeof(linkList));r1=head1;head2=malloc(sizeof(linkList));r2=head2;for(i=0;i<20;i++){s1=malloc(sizeof(linkList));s1->data=i;r1->next=s1;r1=s1;s2=malloc(sizeof(linkList));s2->data=i+2;r2->next=s2;r2=s2;}r2->next=NULL;r1->next=NULL;while(1){printf("theprogram");prin

5、tf("canrealizetocreate,insert,delete,display,etc");printf("1:createtherankedlist");printf("2:insertadata");printf("3:deleteadata");printf("4:displayallthedata");printf("5:Combinetwolinklistsofoperation");printf("6:return,endoftheprogram");printf("selectionofoperation");sc

6、anf("%d",&i);while(i<1

7、

8、i>6){printf("pleaseinputagain");scanf("%d",&i);}switch(i){case1:head=CREATE();break;case2:/*INSERT(p);*/printf("Pleaseinputinsertplace");scanf("%d",&position);printf("Pleaseinputinsertvalue");scanf("%d",&value);INSERT(head,value,position);break;case3:printf(

9、"Pleaseinputdeleteposition");scanf("%d",&value);DELETE(head,position);break;case4:DISPLAY(head);break;case5:printf("Thelist1:");DISPLAY(head1);printf("Thelist2:");DISPLAY(head2);printf("Thecombinelist:");head3=COMBINE(head1,head2);DISPLAY(head3);break;case6:exit(0

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

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

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