【数据结构】3、模拟银行窗口排队叫号系统——C++

本文通过C++编程实现了一个银行窗口排队叫号系统。模拟了银行有4个窗口,当窗口空闲时,新客户可直接办理业务,若所有窗口忙碌,则加入人数最少的窗口等待。客户到达和办理业务的时间均为随机生成。文章通过事件类和队列对象描述系统运行过程。
摘要由CSDN通过智能技术生成

这里我们模拟一下银行排队叫号系统的实现:


假设一个银行有4个窗口对外接待客户。由于每个窗口在某一时刻只能接待一个客户,在客户众多的时候需要排队,对于刚进入银行的客户,如果某个窗口正空闲,
则可上前办理业务,如果所有窗口都不空闲则排在人数最少的窗口。
现在要求模拟银行的某一时间段内的4个窗口的客户排队情况。这里客户到达的时刻和办理业务的时间都是随机的。



首先我们银行发生事件,我们得有一个类表示事件对象

/*
*功能:这个实现的是我们事件的数据单元节点
*文件:Event.h
*时间:2015年7月8日20:55:32
*作者:cutter_point
*/

#ifndef EVENT_H
#define EVENT_H

class Event
{
	int OccurTime;	//事件发生的时刻
	int NType;		//事件类型,0表示到达事件,1到4表示四个窗口的离开事件
public:
	Event() //初始化,我们把事件发生的事件和事件类型都首先视为0
	{
		this->OccurTime = 0;
		this->NType = 0;
	}
	Event(int Occur, int type)
	{
		this->OccurTime = Occur;
		this->NType = type;
	}

	//重写=操作符,运算符的重载
	/*
	Event& operator=(const Event& event)
	{
		if (event == NULL)
		{
		}
	}
	*/

	//set和get方法
	void setOccurTime(int OccurTime) {	this->OccurTime = OccurTime; }
	int getOccurTime() { return this->OccurTime; }
	void setNType(int type) { this->NType = type; }
	int getNType() { return this->NType; }

};

#endif

接着我们用一个链表来存放我们的事件发生链

/*
*功能:这个实现的是链表的功能
*文件:LinkList.h
*时间:2015年7月7日20:33:18,2015年7月8日20:01:31
*作者:cutter_point
*/

#ifndef LINKLIST_H
#define LINKLIST_H

#include "Event.h"
#include <stdio.h>

using namespace std;

//链表的一个节点
class Node
{
	Event event; //创建我们的数据元对象,包含一个事件发生时间和一个事件类型
	Node* next;
public:
	Node() { this->next = nullptr; }
	Node(Event e) { this->event = e; this->next = nullptr; }

	//set和get方法
	void setEvent(Event e) { this->event = e; }
	Event getEvent() { return this->event; }
	void setNext(Node* n) { this->next = n; }
	Node* getNext() { return this->next; }
};

//我们的链表
class LinkList
{
	Node* head;	//头指针
	Node* getTail();	//得到尾部指针
public:
	LinkList(){ this->head = new Node(); }
	void insert(Event e);	//给链表末尾添加一个元素
	Node* pop(); //删除最后一个节点
	bool listEmpty();	//判断是否是空链表
	Node* getHead();	//取得头指针
};

#endif

实现:

/*
*功能:这个实现的是链表的功能
*文件:LinkList.cpp
*时间:2015年7月7日20:33:18,2015年7月8日20:01:31,2015年7月9日20:42:11
*作者:cutter_point
*/

#include "LinkList.h"

#include <iostream>

using namespace std;

/*******************************************************Node****************************************************************************/


/*******************************************************LinkList********************************
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值