银行排号(C语言)

银行为改善服务,设置了排号系统,顾客办理业务时,通过排号机生成一个号码,然后坐在休息区等候排号系统按号码进行呼叫。要求编写程序,模拟排号系统。

BankQueue.c

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
typedef struct{
	int num;//顾客序号 
	long time;//进入队列时间 (顾客取号时间)
}DATA;
#include"CycQueue.h"//顺序循环队列
int num;//顾客序号

void add(CycQueue *q)//新增顾客 
{
	DATA data;
	if(!CycQueueIsFull(q)){//队列未满时 
		data.num=++num;
		data.time=time(NULL);
		CycQueueIn(q,data);
	}
	else printf("\n排队的人太多,请稍后排队!\n");
}

void next(CycQueue *q)//通知下一位办理业务 
{
	DATA *data;
	if(!CycQueueIsEmpty(q)){
		data=CycQueueOut(q);//出队 
		printf("\n请%d号顾客办理业务!\n",data->num);
	}
	if(!CycQueueIsEmpty(q)){
		data=CycQueuePeek(q); 
		printf("请%d号顾客准备\n",data->num);
	}
} 

int main()
{
	CycQueue *q;
	int i,n;
	num=0;
	q=CycQueueInit();
	if(q==NULL){
		printf("创建队列出错!\n");
		getch();
		return 0;
	}
	printf("\nSelect the operation:\n");
	printf("1.New customer arrived\n");//新到顾客 
	printf("2.the next customer\n");//下一个 
	printf("0.exit\n");
	char select;
	fflush(stdin);
	do{
		
		select=getch();
		switch(select){
			case '1':
				add(q);
				printf("There are %d customer waiting.\n",CycQueueLen(q));
				break;
			case '2':
				next(q);
				printf("There are %d customer waiting.\n",CycQueueLen(q));
				break;	
			case '0':
				break;
		}
	}while(select!='0');
	CycQueueFree(q);
	getch();
	return 0;
} 


  • 8
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值