C++ std::queue
std::queue
template <class T, class Container = deque<T> > class queue;
FIFO queue
queues are a type of container adaptor, specifically designed to operate in a FIFO context (first-in first-out), where elements are inserted into one end of the container and extracted from the other.
queues are implemented as containers adaptors, which are classes that use an encapsulated(封装) object of a specific container class as its underlying container, providing a specific set of member functions to access its elements. Elements are pushed into the "back" of the specific container and popped from its "front".
The underlying container may be one of the standard container class template or some other specifically designed container class. This underlying container shall support at least the following operations:
- empty
- size
- front
- back
- push_back
- pop_front
The standard container classes deque and list fulfill these requirements. By default, if no container class is specified for a particular queue class instantiation, the standard container deque is used.
Template parameters
- T: Type of the elements. Aliased as member type queue::value_type.
- Container: Type of the internal underlying container object where the elements are stored. Its value_type shall be T. Aliased as member type queue::container_type.
Member types
member type |definition |notes
--- |--- |
value_type |The first template parameter (T) |Type of the elements
container_type |The second template parameter (Container) |Type of the underlying container
size_type |an unsigned integral type |usually the same as size_t
Member functions
- (constructor): Construct queue (public member function )
- empty: Test whether container is empty (public member function )
- size: Return size (public member function )
- front: Access next element (public member function )
- back: Access last element (public member function )
- push: Insert element (public member function )
- emplace: Construct and insert element (public member function )
- pop: Remove next element (public member function )
- swap: Swap contents (public member function )
Non-member function overloads
- relational operators: Relational operators for queue (function )
- swap (queue): Exchange contents of queues (public member function )
Non-member class specializations
- uses_allocator: Uses allocator for queue (class template )
Code Example
#include <iostream>
#include <deque>
#include <list>
#include <queue>
using namespace std;
int main(int argc, char **argv)
{
deque<int> deck (3, 100);
list<int> list (2, 200);
queue<int> first;
queue<int> first1( deck ); ///< queue initialized to copy of deque
/** empty queue with list as underlying container */
queue<int, list<int> > first2;
/** */
queue<int, list<int> > first3 ( list );
return 0;
}
Reference
C++ std::queue的更多相关文章
- 从deque到std::stack,std::queue,再到iOS 中NSArray(CFArray)
从deque到std::stack,std::queue,再到iOS 中NSArray(CFArray) deque deque双端队列,分段连续空间数据结构,由中控的map(与其说map,不如说是数 ...
- C++11:基于std::queue和std::mutex构建一个线程安全的队列
C++11:基于std::queue和std::mutex构建一个线程安全的队列 C++中的模板std::queue提供了一个队列容器,但这个容器并不是线程安全的,如果在多线程环境下使用队列,它是不能 ...
- 问题解决——在STL的queue中使用自定义类
本文原创,转载请保证文章的完整性,并显要的注明出处. 本文链接:http://blog.csdn.net/wlsgzl/article/details/38843513 平时很少用STL,就算用,也基 ...
- 容器适配器之queue
转载http://blog.csdn.net/thefutureisour/article/details/7751846容器适配器容器适配器其实就是一个接口转换装置,使得我们能用特定的方法去操作一些 ...
- leetcode:Implement Stack using Queues 与 Implement Queue using Stacks
一.Implement Stack using Queues Implement the following operations of a stack using queues. push(x) - ...
- uva 12100 Printer Queue
The only printer in the computer science students' union is experiencing an extremely heavy workload ...
- uva 10935 throwing cards away <queue>
Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n ...
- #include <queue>
双端队列deque比向量vector更有优势 双端队列(deque) 连续存储的指向不同元素的指针所组成的数组<deque> 队列(queue) 先进先出的值的排列 <queue&g ...
- C++标准库之queue(各函数及其使用全)
原创作品,转载请注明出处:http://www.cnblogs.com/shrimp-can/p/5283520.html 一.FIFO队列,即先入先出队列 1.队列的声明 std::deque< ...
随机推荐
- ASP.NET Aries 入门开发教程3:开发一个列表页面及操控查询区
前言: Aries框架毕竟是开发框架,所以重点还是要写代码的,这样开发人员才不会失业,哈. 步骤1:新建html 建一个Html,主要有三步: 1:引入Aries.Loader.js 2:弄一个tab ...
- 挑子学习笔记:特征选择——基于假设检验的Filter方法
转载请标明出处: http://www.cnblogs.com/tiaozistudy/p/hypothesis_testing_based_feature_selection.html Filter ...
- addTwoNumbers
大神的代码好短,自己写的120多行=_= 各种判断 ListNode *f(ListNode *l1, ListNode *l2) { ListNode *p1 = l1; ListNode *p2 ...
- 修改session垃圾回收几率
<?php //修改session垃圾回收几率 ini_set('session.gc_probability','1'); ini_set('session.gc_divisor','2'); ...
- 发布APP到app store
好久好久没写博客了,主要是 都在学习新东西,忙不赢啊. 近段时间在用AC平台学习开发移动APP, 今天开始发布应用. 在ac云控制台编译成ipa后,使用apple提供的Application Load ...
- 安装devtoolset
在运维的工作内,经常要编译安装各种开源组件,以CentOS 6的用户来说,大部分时候用到gcc的时候都是4.4.7版本的,在绝大多数情况下编译一些东西还是够用的,但还是有个别软件对gcc的版本是有要求 ...
- 完整部署CentOS7.2+OpenStack+kvm 云平台环境(1)--基础环境搭建
公司在IDC机房有两台很高配置的服务器,计划在上面部署openstack云平台虚拟化环境,用于承载后期开发测试和其他的一些对内业务.以下对openstack的部署过程及其使用做一详细介绍,仅仅依据本人 ...
- 从贝叶斯到粒子滤波——Round 1
粒子滤波确实是一个挺复杂的东西,从接触粒子滤波到现在半个多月,博主哦勒哇看了N多篇文章,查略了嗨多资料,很多内容都是看了又看,细细斟酌.今日,便在这里验证一下自己的修炼成果,请各位英雄好汉多多指教. ...
- 使用CocosSharp制作一个游戏 - CocosSharp中文教程
注:本教程翻译自官方<Walkthrough - Building a game with CocosSharp>,官方教程有很多地方说的不够详细,或者代码不全,导致无法继续,本人在看了G ...
- 如何设计一门语言(七)——闭包、lambda和interface
人们都很喜欢讨论闭包这个概念.其实这个概念对于写代码来讲一点用都没有,写代码只需要掌握好lambda表达式和class+interface的语义就行了.基本上只有在写编译器和虚拟机的时候才需要管什么是 ...