c++队列模板类的定义在<queue>头文件中,queue 模板类需要两个模板参数,一个是元素类型,一个容器类型,元素类型是必要的,容器类型是可选的,默认为deque 类型。

下面详细介绍queue的使用:

一:定义queue(要有头文件#include <queue>)

queue<int> q1;
queue<double> q2;

二:基本函数

back()返回一个引用,指向队列的最后一个元素。

empty()函数返回真(true)如果队列为空,否则返回假(false)。

front()返回队列第一个元素的引用。

pop()函数删除队列的一个元素

push() 在末尾加入一个元素

size() 返回队列中元素的个数

三:示例代码

#include <cstdlib>
#include <iostream>
#include <queue>
using namespace std;
int main()
{
int e,n,m;
queue<int> q1;
for(int i=0;i<10;i++)
q1.push(i);
if(!q1.empty())
cout<<"dui lie bu kongn";
n=q1.size();
cout<<n<<endl;
m=q1.back();
cout<<m<<endl;
for(int j=0;j<n;j++)
{
e=q1.front();
cout<<e<<" ";
q1.pop();
}
cout<<endl;
if(q1.empty())
cout<<"dui lie bu kongn";
system("PAUSE");
return 0;
}

最新文章

  1. 传输层协议TCP和UDP
  2. 夯实基础之php学习-1基础篇
  3. 【OpenCV】边缘检测:Sobel、拉普拉斯算子
  4. 亚马逊如何变成 SOA(面向服务的架构)?
  5. jq 文字上下不间断滚动实例
  6. static_cast .xml
  7. c 语言结构体struct的三种定义方式 及 typedef
  8. ASP.NET性能优化小结
  9. [前言] 实现一个Android电子书阅读APP
  10. 【前端】主流API-promise解析,js基础。
  11. 用C#操作IIS创建虚拟目录和网站
  12. Python中的数据结构
  13. Archive required for library “xxx” cannot be read or is not a valid zip file报错解决
  14. Pandas 基础(2) - Dataframe 基础
  15. noip第7课资料
  16. threejs精灵平面Sprite(类似tip效果)
  17. iOS字符串安全
  18. Ubuntu 16.04.5安装docker
  19. net core集成CAP
  20. 让Outlook一直保持开启

热门文章

  1. LInux下实时网络流量监控工具nload教程
  2. POJ 1066
  3. html里显示中文乱码的解决的方法
  4. 支持中文的基于词为基本粒度的前缀树(prefix trie)python实现
  5. UVa 10290 - {Sum+=i++} to Reach N
  6. UVA - 11077 Find the Permutations (置换)
  7. 微软继MVC5后,出现ASP.NET VNEXT
  8. [JavaEE] 了解Java连接池
  9. SQL注入原理解析以及举例1
  10. MYSQL5.6和5.7编译标准化安装与配置