预览加载中,请您耐心等待几秒...
在线预览结束,喜欢就下载吧,查找使用更方便
如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
上机实验报告计科093班孙浩川200910405310实验内容:线性表链式存储的基本操作程序清单:#include<stdio.h>#include<stdlib.h>typedefintElemtype;#defineMax20typedefstructnode{Elemtypedata;structnode*next;}LNODE,*Linklist;LinklistCreatLinklist(intn){Linklistp,r,list=NULL;Elemtypee;inti;for(i=0;i<n;i++){scanf("%d",&e);p=(Linklist)malloc(sizeof(LNODE));p->data=e;p->next=NULL;if(!list)list=p;elser->next=p;r=p;}returnlist;}voidInsertLinklist(Linklist*list,Linklistq,Elemtypee){Linklistp;p=(Linklist)malloc(sizeof(LNODE));p->data=e;if(!*list){*list=p;p->next=NULL;}else{p->next=q->next;q->next=p;}}voidDelLinklist(Linklist*list,Linklistq){Linklistr;if(q==*list){*list=q->next;free(q);}else{for(r=*list;r->next!=q;r=r->next);if(r->next!=NULL){r->next=q->next;free(q);}}}voidDestroyLinklist(Linklist*list){Linklistp,q;p=*list;while(p){q=p->next;free(p);p=q;}*list=NULL;}voidmain(){Linklistq,l;Elemtypee;inti;q=l=CreatLinklist(1);printf("pleaseinputmorethan10numbersandendwith0\n");scanf("%d",&e);while(e!=0){InsertLinklist(&l,q,e);q=q->next;scanf("%d",&e);}printf("outputthenumbers:\n");q=l;for(;q!=NULL;q=q->next)printf("%d\n",q->data);q=l;for(i=0;i<4;i++)q=q->next;DelLinklist(&l,q);printf("afterdeloutputtheanswer:\n");q=l;while(q!=NULL){printf("%d\n",q->data);q=q->next;}printf("destroyLinklist\n");DestroyLinklist(&l);}运行结果:心得体会:通过本次上机实验,逐渐掌握了顺序表链式存储的基本概念,熟悉了指针及链表的使用,为以后数据结构的学习奠定基础。