预览加载中,请您耐心等待几秒...
1/5
2/5
3/5
4/5
5/5

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

实验报告课程数据结构(Ⅲ)实验项目2、链表的应用成绩专业班级测绘工程2010级指导教师岳静姓名许国徽学号1008030214实验日期2011-12-21实验目的:学会使用线性表的链式存储表示设计应用算法实验内容:设有一线性表表,表中元素递增有序,请设计一个程序,将X插入到线性表中适当的位置,以保持线性表的有序性,要求:以单链表作为存储结构。选作:将线性表A=(a1,a2,…am),B=(b1,b2,…bn)合并成线性表C,C=(a1,b1,a2,b2,…am,bm,bm+1,…bn)(当m<=n时),或C=(a1,b1,a2,b2,…an,bn,an+1,…am)(当m>n时),要求线性表A,B,C均用单链表作为存储结构,且C表利用A表和B表的结点空间构成。实验代码:#include<stdio.h>#include<malloc.h>#defineLENsizeof(structnode)structnode{intnum;structnode*next;};intn;structnode*creat(){structnode*head;structnode*p1,*p2;n=0;p1=p2=(structnode*)malloc(LEN);scanf("%d",&p1->num);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structnode*)malloc(LEN);scanf("%d",&p1->num);}p2->next=NULL;return(head);}voidprint(structnode*head){structnode*p;printf("\nThelistis:\n");p=head;while(p!=NULL){printf("%4d",p->num);p=p->next;}printf("\n");}intlocate(structnode*head,intn){structnode*p;inti=1;p=head;while(p->num<n&&p->next!=0){p=p->next;i++;}returni;}voidInsList(structnode*head,inti,inte){structnode*p;structnode*s;p=head;intj=1;while(p&&j<i-1){p=p->next;++j;}if(!p||j>i-1)printf("wrong\n");s=(structnode*)malloc(LEN);s->num=e;s->next=p->next;p->next=s;}voidmain(){intn,m;structnode*L;L=creat();print(L);scanf("%d",&m);n=locate(L,m);InsList(L,n,m);print(L);}实验结果:实验小结: