《四海小记c++学习之路》队列/银行叫号系统
生活随笔
收集整理的這篇文章主要介紹了
《四海小记c++学习之路》队列/银行叫号系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
寫在前面的話:
這個是用隊列實現的銀行叫號系統
/************************************** 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;}}}elsecout << "你按錯啦!" << endl;} }總結
以上是生活随笔為你收集整理的《四海小记c++学习之路》队列/银行叫号系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 你为什么喜欢VIM?
- 下一篇: python进阶中文版_GitHub -