博客
关于我
算法C++ 先进先出队列银行排号系统STL库实现(第一章)
阅读量:201 次
发布时间:2019-02-28

本文共 842 字,大约阅读时间需要 2 分钟。

造轮子博客链接


代码实现

#include   #include   using namespace std;  int main(){ int temp; int customers_count = 0; unsigned maxnumber = 10; //银行今天接待人数限制 queue number_line; cout << "bank only receive " << maxnumber << " people today" << endl;  cout << "customers over maxnumber or input '-1' stop serving" << endl;  cout << "input your number" << endl;  while (cin >> temp) {      if (temp == -1 || number_line.size() == maxnumber) {          if (number_line.size() == maxnumber) {              cout << "sorry the customers are too many! please next day comes!" << endl;          }          break;      }      number_line.push(temp);  }  return 0;  }


实现效果

通过这个简单的程序,我们可以模拟一个银行接待人数的系统。程序使用队列数据结构来管理接待的顾客数量,当达到最大值时会提示顾客下次来店。

程序的主要逻辑是:读取用户输入的数字,直到达到最大值10或用户输入-1为止。输入的数字会被添加到队列中,队列的大小限制了接待人数。当队列达到最大值时,程序会提示"抱歉,今天的人数太多了,请下次再来"。

这个程序简单实用,适合用于教学或演示队列数据结构的基本应用。

转载地址:http://mfni.baihongyu.com/

你可能感兴趣的文章
Openwrt LuCI模块练习详细步骤
查看>>
openwrt_git_pull命令提示merger冲突时如何解决?
查看>>
OpenWrt包管理软件opkg的使用(极路由)
查看>>
OpenWrt固件编译刷机完全总结
查看>>
Open××× for Linux搭建之二
查看>>
Open×××有线网络时使用正常,无线网络时使用报错的解决方案
查看>>
Opera Mobile Classic Emulator
查看>>
Operation not supported on read-only collection 的解决方法 - [Windows Phone开发技巧系列1]
查看>>
OperationResult
查看>>
Operations Manager 2007 R2系列之仪表板(多)视图
查看>>
operator new and delete
查看>>
operator new 与 operator delete
查看>>
operator() error
查看>>
OPPO K3在哪里打开USB调试模式的完美方法
查看>>
oppo后端16连问
查看>>
Optional类:避免NullPointerException
查看>>
Optional讲解
查看>>
ORA-00932: inconsistent datatypes: expected - got NCLOB【ORA-00932: 数据类型不一致: 应为 -, 但却获得 NCLOB 】【解决办法】
查看>>
ORA-00942 表或视图不存在
查看>>
ORA-01034: ORACLE not available
查看>>