写在前面的话:
这个是用队列实现的银行叫号系统
/**************************************
Copyright Burp
Author: created by Burp
Date: 2020-10-27
Description: 队列
Version: 1.0
**************************************/
#include <iostream>
using namespace std;
class Node // 节点
{
public:
int element;
Node* next;
};
class List {
public:
List()
{
head = new Node;
head->next = NULL;
tail = NULL;
temp = 0;
}
~List()
{
delete head;
delete tail;
}
void push();//添加
void pop();//删除
bool size(const int& number);//读取当前人数
private:
int temp;
Node* tail;
Node* head;
};
/**************************************
Fuction: push
Description: 加号
Input:
Output:
Return: void
Others:
**************************************/
void List::push()
{
Node* user = new Node;
Node* puser = NULL;
if (temp < 1)
{
user->next = NULL;
head->next = user;
tail = user;
user->element = temp;
temp++;
}
else
{
puser = head->next;
while (true)
{
if (puser->next == NULL)
{
user->next = NULL;
puser->next = user;
tail = user;
user->element = temp;
temp++;
break;
}
puser = puser->next;
}
}
cout << "当前大厅还有" << temp << "人!" << endl;
}
/**************************************
Fuction: pop
Description: 删除
Input:
Output:
Return: void
Others:
**************************************/
void List::pop()
{
Node* puser = NULL;
puser = head->next;
head->next = puser->next;
temp--;
delete puser;
cout << "\n当前大厅还有" <<temp<< "人!" << endl;
}
/**************************************
Fuction: size
Description: 读取当前人数
Input: SeqList &L
Output:
Return: bool
Others:
**************************************/
bool List::size(const int& number)
{
if (number < 0 || number > tail->element)
{
cout << "该号码不存在!" << endl;
return false;
}
else
{
Node* puser = NULL;
puser = head->next;
cout << "你的前面还有" << number-1 - puser->element << "人!" << endl;
return true;
}
}
int main()
{
List list;
int key;
while (true)
{
cout <<
"-------------------------\n"
"1-处理业务\n"
"2-业务处理完毕\n"
"3-查讯你的前面还有多少人\n"
"0-退出\n"
"-------------------------\n"
"请选择业务:";
cin >> key;
if (key >= 0 && key < 4)
{
switch (key)
{
case 0:return 0;
case 1:list.push(); break;
case 2:list.pop(); break;
case 3:
{
int number;
cout << "请输入你的号码:";
cin >> number;
list.size(number);
break;
}
}
}
else
cout << "你按错啦!" << endl;
}
}