欢迎来到天天文库
浏览记录
ID:35342730
大小:116.33 KB
页数:5页
时间:2019-03-23
《数据结构队列的相关操作》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、/*队列的相关操作*/#include#definemaxsize100#definen10typedefintdatatype;typedefstruct{datatypedata[maxsize];intfront,rear;Jsequeue;sequeue*sq;厂置空队*/SETNULL(sq)sequeue*sq;{sq->front=maxsize-l;sq->rear=maxsize-l;printf("Setnullover!");}/*判队空*/intEMPTY(sq)sequeue*sq
2、;{if(sq->rear==sq->front)return1;elsereturn0;}厂取队头元素*/datatypeFRONT(sq)sequeue*sq;{if(EMPTY(sq)){printf("Thequeueisempty!");returnNULL;}elseprintf(,,Front:n);printf("%d",(sq->data[(sq->front+l)%maxsize]));return(sq->data[(sq->front+l)%maxsize]);严入队*/intENQUEUE(sq,x
3、)sequeue*sq;datatypex;{inta[n];inti;for(i=0;ivn;i++){scanf("%d",&a[i]);x=a[i];if(sq->front==(sq->rear+l)%maxsize){printff'Thequeueisfull!");returnNULL;}else{sq->rear=(sq->rear+l)%maxsize;sq->data[sq->rear]=x;printf("%d,,,sq->data[sq->rear]);}}returnsq;}厂出队datatypeD
4、EQUEUE(sq)sequeue*sq;{if(EMPTY(sq))printf("Thequeueisempty!");else{sq->front=(sq->front+l)%maxsize;printf("%d",sq->data[sq->front]);return(sq->data[sq->front]);}}厂主函数*/voidmain()intc;doprintf("**********************************************************************
5、*♦******♦!«).printf("ttttZhanxiangguancaozuo”);printff'");printf("ttlt2t3t4t5t6");printf(HH);printf('、ttSetnullEmptyFrontEnqueueDequeueExit1');printf(H***********************************************************************♦*******H).printf(H
6、Pleaseenteryourchoice:");scanf「%d':&c);switch(c)case1:{SETNULL(sq);printf("ContinueH);}break;case2:{EMPTY(sq);if(EMPTY(sq))prin廿("Thequeueisempty!");elseprintf("Thequeueisnotempty!");printf("Continue");}break;case3:{FRONT(sq);printf("Continue");}break;c
7、ase4:{datatypex;printf("Pleaseinputyourdatas:");ENQUEUE(sq,x);printf("Continue");}break;case5:DEQUEUE(sq);printf("Continue");}break;case6:exit(0);break;}}while(c!=6);getch();}运行结果为:入队:Zhanxiangguancaozuo123456SetnullEmptyFrontEnqueueDequeueExit兴兴兴兴兴兴兴兴兴兴兴
8、兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴兴務Pleaseenteryourchoice:4Pleaseinputyourdatas:123456789033669988123456789033669988Continue取队头元索:Zh
此文档下载收益归作者所有