单链表队列数据结构实验报告及结果

单链表队列数据结构实验报告及结果

ID:20594457

大小:73.55 KB

页数:7页

时间:2018-10-14

单链表队列数据结构实验报告及结果_第1页
单链表队列数据结构实验报告及结果_第2页
单链表队列数据结构实验报告及结果_第3页
单链表队列数据结构实验报告及结果_第4页
单链表队列数据结构实验报告及结果_第5页
资源描述:

《单链表队列数据结构实验报告及结果》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、#include#defineNULL0typedefstructInode{intdata;structInode*next;}linklist;linklist*create(void){linklist*head,*pl,*p2;intn;n=0;pi=p2=(linklist*)malloc(sizeof(linklist));printf(”inputdatas:");scanf(H%d'&pl->data);head=NULL;while(pl->data!=0){n=n+l;if(

2、n==l)head=p1;elsep2->next=pl;p2=pl;pl=(linklist*)malloc(sizeof(linklist));scanf("%d’’,&p1->data);}p2-〉next=NULL;returnhead;}voidchaxun(linklist*head,intx){linklist*pl=head;inti=0;while(p1-〉data!=x&&p1!=NULL){pl=pl-〉next;i=i+l;}if(pl!=NULL)printf("thepositionis:%

3、d",i+l);elseprintf("xisnotbeenfound");}linklist*insert(linklist*head,linklist*stud)linklist*pl,*p2,*p0;pi=head;pO=stud;if(head==NULL){head=pO;pO->next=NULL;}else{while((pO->data>pI->data)&&(pI->next!=NULL)){p2=pl;pl=pl->next;}if(pO->data

4、ad=pO;elsep2-〉next=p0;pO->next=pl;}else{pl->next=pO;pO-〉next=NULL;}}returnhead;)linklist*del(linklist*head,intnum){linklist*pl,*p2;if(head==NULL){prinlf(”listnull!");returnhead;}pl=head;while(num!=pl-〉data&&p1->next!=NULL){p2=p1;p1=p1-〉next;}if(num==p1->data){

5、if(pl==head)head=pl->next;elsep2->next=p1->next;printf("deletse:%d",num);returnhead;voidprinf(linklist*head){linklist*p;p=head;while(p!=NULL){printf(’’%5dn,p-〉data);p=p->next;}printf(H");}voidmain(){intx,y,t;linklist*head=NULL;linklist*stud;head=create();pri

6、nf(head);printf(■’Inputadatatoinsert:’’);stud=(linklist*)malloc(sizeof(linklist));scanf(H%d",&stud->data);insert(head,stud);prinf(head);printf(•’Inputadatatoquery:");scanf(’’%cT’,&y);chaxun(head,y);printf(”Inputadatatodelete:n);scanf("%d",&t);del(head,t);p

7、rinf(head);■□

8、x:▲Inputadata12to3tres4n:DociuientsandSettingsAd>inistrator桌面c++DebugCppl.exe*inputdatas:123456012345Inputadatatoquery:5thepositionis:5Inputadatatodelete:deletse:412356PressanykeytocontinueI-#include#include#definemaxsize16ty

9、pedefcharqueuetype;typedefstruct{queuetype*base;intfront;intrear;}queue;queue*xinjian(queue*q){queue*p=q;p->base=(queuetype*)malloc(maxsize*sizeof(queue

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

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

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