日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

《四海小记c++学习之路》队列/银行叫号系统

發布時間:2023/12/20 c/c++ 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 《四海小记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++学习之路》队列/银行叫号系统的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。