资源描述:
《实验二 链表的实现和应用》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
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