简单的银行排号叫号

以下内容仅供个人参考,本人初学者,在技术上有诸多不足,请高手指点!


#include "stdafx.h"
#include <stdlib.h>

#define MAXSIZE_T 100//队列最大长度;
#define INCREATSIZE 10
#define OVERFLOW -1
#define OK 1
#define ERROR -2
typedef struct QNode
{
	int data;
	struct QNode *next;
}*QPtr;//队列中每个客户是一个节点;

typedef struct 
{
	QPtr front;//头指针;
	QPtr rear;//尾指针;
}Squeue;//客户到达生成的队列;

int initQueue(Squeue &L)//初始化队列;
{
	L.front = L.rear = (QPtr)malloc(MAXSIZE_T*sizeof(int));
	if (!L.front)
		exit(OVERFLOW);
	L.front->next =NULL;
	return OK;
}

void EnQueue(Squeue &L,int e)//进队列;
{
	QPtr p;
	printf("建立一个队列:\n");
	scanf_s("%d", &e, sizeof(e));
	while (e)
	{
		p = (QPtr)malloc(MAXSIZE_T + INCREATSIZE * sizeof(int));
		if (!p)
			exit(OVERFLOW);
		p->data = e;
		p->next = NULL;
		L.rear->next = p;
		L.rear = p;
		scanf_s("%d", &e, sizeof(e));
	}
}

int DeQueue(Squeue &L, int e)//出队列;
{
	QPtr p;
	if (L.front == L.rear)
		return ERROR;
	p = L.front->next;
	e = p->data;
	L.front->next = p->next;
	if (L.rear == p)
		L.rear = L.front;
	free(p);
	return e;
}

int _tmain(int argc, _TCHAR* argv[])
{
	Squeue L;
	int e=NULL,i,t;
	int w1,w2,w3,w4;
	char BQ[5] = {};
	char BT[] = { 'A', 'B', 'C', 'D' };
		//4个办理业务窗口;
	initQueue(L);
	EnQueue(L,e);
	printf("\n窗口序号为:%c %c %c %c\n", BT[0], BT[1],BT[2],BT[3]);
	printf("\n请输入窗口状态(0为没人,1为有人):\n");
	scanf_s("%d %d %d %d", &w1, &w2, &w3, &w4);
	BQ[0] = w1; 
	BQ[1] = w2;
	BQ[2] = w3; 
	BQ[3] = w4;
	printf("\n窗口状态为,%c=%d  %c=%d  %c=%d  %c=%d \n", BT[0], w1, BT[1], w2, BT[2], w3, BT[3], w4);
	for (i = 0; i < 4; i++)
	{
		if (BQ[i] == 0)
		{
			t = DeQueue(L, e);
			printf("\n请%d号到%c窗口办理业务;\n", t, BT[i]);
		}
		else
		{
			printf("\n窗口有人,请稍等;\n");
		}
	}
	return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值