队列应用一例

#include <stdio.h>
#define max 50
int queue[max],front=0,rear=0;
void enque()
{
 if((rear+1)%max==front)
  printf("队已经排满了=_+!/t请等待……");
 else
 {
 int his,ck=0;
 printf("请输入病人的病历号:(6位纯数字)");
 while (ck==0)
 { scanf("%d",&his);
 if(his<1000000&&ck>=0)ck=1;
 else printf("请重新输入病人的病历号:(6位纯数字)");
 }
 rear=(rear+1)%max;
 queue[rear]=his;
 
 }
   system("pause");
}
void treat()
{
 if(front==rear)
  {
   printf("现在没有病人排队,请等一会儿……/n");
  }
 else
 {
  printf("%6d已就诊。/n",queue[(front+1)%max]);
  front=(front+1)%max;
 }
   system("pause"); 
}
void  disque()
{ int n=0;
 printf("下班了,大家都回去吧。/n");
 while(front!=rear)
 {
  printf("病人:%6d  ",queue[(front+1)%max]);
  n++;
  if(n%5==0)printf("/n");
  front=(front+1)%max; 
 }printf("/n");
 system("pause");
 exit(0);
}
void check()
{
 int n,i;
  
 if(front==rear)
  {
   printf("现在没有病人排队,请等一会儿……/n");
  }
 else
 {
  i=front;
  while(i!=rear)
  { n++;
  if(n%5==0)printf("/n");
   printf("病人:%6d  ",queue[(i+1)%max]);
   i=(i+1)%max;
  }printf("/n");
 }
 system("pause");
}
int main()
{ int opration;
 system("title 挂号-就诊 系统[医]");
 system("color f1");
  while(1)
  {
  printf("/t/t①排队 ②就诊 ③查看排队 ④不在排队 ⑤下班/n/n请输入您要进行的操作:");
  scanf("%d",&opration);
  switch (opration)
  {
   case 1:enque();break;
   case 2:treat();break;
   case 3:check();break;
   case 4:disque();break;
   case 5:exit(0);
   default :{printf("请输入正确的选项。/n");system("pause");}
  }
  system("cls");
  }
  
 return 0;
 
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值