欢迎来到天天文库
浏览记录
ID:20594457
大小:73.55 KB
页数:7页
时间:2018-10-14
《单链表队列数据结构实验报告及结果》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
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->data4、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();pri6、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);p7、rinf(head);■□8、x:▲Inputadata12to3tres4n:DociuientsandSettingsAd>inistrator桌面c++DebugCppl.exe*inputdatas:123456012345Inputadatatoquery:5thepositionis:5Inputadatatodelete:deletse:412356PressanykeytocontinueI-#include#include#definemaxsize16ty9、pedefcharqueuetype;typedefstruct{queuetype*base;intfront;intrear;}queue;queue*xinjian(queue*q){queue*p=q;p->base=(queuetype*)malloc(maxsize*sizeof(queue
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
此文档下载收益归作者所有