#include "stdio.h" #define maxsize 50 typedef int elemtype;
typedef struct {elemtype data[maxsize]; int front,rear; } queue; elemtype e;
/***********************************************/ void init_queue(queue *h) {h->front=h->rear=0; } /********************************************/ int empty_queue(queue h) {return h.front==h.rear;} /********************************************/ int full_queue(queue h) {return (h.rear+1)%maxsize==h.front;} /********************************************/ void append_queue(queue *p) {int i,n,line; clrscr(); line=10; gotoxy(20,line); printf("How many numbers which you will append ?"); scanf("%d",&n); i=0; while(i<n) { if(full_queue(*p)) {clrscr(); gotoxy(16,11); printf("Sorry ! The queue is full ! Cann't append it!"); break; } else { line=line+2; if(line>24) {clrscr();line=2;} gotoxy(20,line); printf("Please input NO.%d number:",i+1); scanf("%d",&e); p->rear=(p->rear+1)%maxsize; p->data[p->rear]=e; } i++; } getch(); } /*****************************************************/ void output(queue h) {int i,num=0; clrscr(); gotoxy(20,10); if(empty_queue(h)) printf("Sorry ! The queue is emtpy ! "); else {printf(" "); for(i=h.front;i!=h.rear;) {i=(i+1)%maxsize; printf("%5d",h.data[i]);num++; if(num%10==0)printf(" "); } } gotoxy(20,22); printf("Press Any key to Return ."); getch(); } /********************************************/ void delete_queue(queue *h) { clrscr(); gotoxy(20,11); if(empty_queue(*h)) printf("Sorry ! The queue is emtpy ! "); else { e=h->data[h->front+1]; h->front=(h->front+1)%maxsize; printf("The element that came out is %d. ",e); } getch(); } /********************************************/ void getelem(queue h,elemtype *p) { clrscr(); gotoxy(20,11); if(empty_queue(h)) printf("Sorry ! The queue is emtpy ! "); else { *p=h.data[h.front+1]; printf("The elemment which you get is %d.",*p); } getch(); } /********************************************/ void quit() { clrscr(); gotoxy(20,12); printf("e use it again ! "); getch(); exit(0); } /********************************************/ void main() { int n; queue qe; init_queue(&qe);
while(1) {clrscr(); gotoxy(20,7); printf(" ===== menu ===== "); gotoxy(20,9); printf("******************************** "); gotoxy(20,10);printf("* 1. append 2. deleted * "); gotoxy(20,11);printf("* 3. getelem 4. output * "); gotoxy(20,12);printf("* 0. quit * "); gotoxy(20,13);printf("******************************** "); gotoxy(20,16); printf("Please input your choice : "); scanf("%d",&n); while(n<0||n>4) {printf(" Input Error ! Please input again ! "); scanf("%d",&n); } switch(n) {case 1:append_queue(&qe); break; case 2:delete_queue(&qe); break; case 3:getelem(qe,&e); break; case 4:output(qe); break; case 0:quit(); } } }
pigyun怎么样?PIGYun成立于2019年,2021是PIGYun为用户提供稳定服务的第三年,期待我们携手共进、互利共赢。PIGYun为您提供:香港CN2线路、韩国CN2线路、美西CUVIP-9929线路优质IaaS服务。月付另有通用循环优惠码:PIGYun,获取8折循环优惠(永久有效)。目前,PIGYun提供的香港cn2云服务器仅29元/月起;韩国cn2云服务器仅22元/月起;美国CUVI...
hostodo怎么样?快到了7月4日美国独立日,hostodo现在推出了VPS大促销活动,提供4款Hostodo美国独立日活动便宜VPS,相当于7折,低至$13/年,续费同价。Hostodo美国独立日活动结束时间不定,活动机售完即止。Hostodo商家支持加密数字货币、信用卡、PayPal、支付宝、银联等付款。Hostodo美国独立日活动VPS基于KVM虚拟,NVMe阵列,1Gbps带宽,自带一个...
易探云香港vps主机价格多少钱?香港vps主机租用费用大体上是由配置决定的,我们选择香港vps主机租用最大的优势是免备案vps。但是,每家服务商的机房、配置、定价也不同。我们以最基础配置为标准,综合比对各大香港vps主机供应商的价格,即可选到高性能、价格适中的香港vps主机。通常1核CPU、1G内存、2Mbps独享带宽,价格在30元-120元/月。不过,易探云香港vps主机推出四个机房的优惠活动,...