酒窝女孩在学完数据结构后做了一个这样的银行叫号系统,该系统只是巩固一下我数据结构的知识。
#include<stdio.h>
#include<string.h>
#include<stack>
#include<queue>
#define MAXQSIZE 101//实际可排100个号
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
int IsInit = FALSE;
typedef int ElemType;
typedef int Status;
typedef struct
{
ElemType data[MAXQSIZE];
int front;
int rear;
}SqQueue;
Status QueueEmpty(SqQueue Q)//判断队列是否为空
{
if (Q.front == Q.rear)
return TRUE;
else
return FALSE;
}
Status QueueFull(SqQueue Q)//判断队列是否已满
{
if ((Q.rear + 1) % MAXQSIZE == Q.front)
return TRUE;
return FALSE;
}
Status EnQueue(SqQueue& Q, ElemType e)//元素e入队尾
{
if (QueueFull(Q)) return ERROR;
Q.data[Q.rear] = e;
Q.rear = (Q.rear + 1) % MAXQSIZE;
return OK;
}
Status DeQueue(SqQueue& Q, ElemType& e)//元素e出队,并用e来返回
{
if (QueueEmpty(Q)) return ERROR;
e = Q.data[Q.front];
Q.front = (Q.front + 1) % MAXQSIZE;
return OK;
}
void InitQueue(SqQueue& Q)//队列初始化,同时让标记变量IsInit标记为TRUE;
{
Q.front = Q.rear = 0;
IsInit = TRUE;
}
Status GetHead(SqQueue Q, ElemType& e)//获得队头元素
{
if (QueueEmpty(Q)) return ERROR;
e = Q.data[Q.front];
return OK;
}
int QueueLength(SqQueue Q)//求队列长度
{
return (Q.rear + MAXQSIZE - Q.front) % MAXQSIZE;
}
int main()
{
int slt, num = 0;
int star = 0;
SqQueue Q;
ElemType e;
while (1)
{
printf("===========银行排号叫号模拟系统功能菜单============\n");
printf("===================================================\n");
printf("1:开始上班\n");
printf("2:排号\n");
printf("3:叫号\n");
printf("4:评价业务\n");
printf("0:下班\n");
printf("===================================================\n");
scanf("%d", &slt);
switch (slt)
{
case 0:if (!IsInit)
{
printf("请先选择开始上班,做好准备工作!\n\n");
break;
}
if (QueueEmpty(Q))
{
printf("@@今天下班,快乐回家!\n\n");
return 0;
}
else
{
printf("@@目前还有排号未办理业务的顾客,暂不能下班哦,加油!\n\n");
break;
}
case 1:IsInit = TRUE;
if (!IsInit)
{
printf("Q@@请先选择开始上班,做好准备工作!\n\n");
break;
}
InitQueue(Q);
printf("@@准备就绪,一天新的开始有个好心情!\n\n");
break;
case 2:if (!IsInit)
{
printf("@@请先选择开始上班,做好准备工作!\n\n");
break;
}
if (!QueueFull(Q))
{
EnQueue(Q, ++num);
printf("@@当前是%d号,前面还有%d人等待。\n\n", num, QueueLength(Q) - 1);
}
else
printf("@@人数已满!!!\n\n");
break;
case 3:if (!IsInit)
{
printf("请先选择开始上班,做好准备工作!\n\n");
break;
}
if (DeQueue(Q, e))
printf("@@%d号顾客业务办理成功,谢谢下次光临!目前还有%d个人等待办理。\n\n", e, QueueLength(Q));
else
printf("@@目前暂无需要办理业务的顾客!!!\n\n");
break;
case 4:
printf("请评价我们的服务(一星到五星):\n");
scanf("%d", &star);
printf("谢谢评价,我们会继续努力的哦!\n");
break;
default:printf("@@无效操作,请重新选择菜单!\n\n");
break;
}
}
return OK;
}