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< ...
随机推荐
- excel 日期/数字格式不生效需要但双击才会生效的解决办法
原因: Excel2007设置过单元格格式后,并不能立即生效必须挨个双击单元格,才能生效.数据行很多.效率太低. 原因:主要是一些从网上拷贝过来的日期或数字excel默认为文本格式或特殊-中文数字格式 ...
- 0.Win8.1,Win10,Windows Server 2012 安装 Net Framework 3.5
后期会在博客首发更新:http://dnt.dkill.net 网站部署之~Windows Server | 本地部署:http://www.cnblogs.com/dunitian/p/482280 ...
- DDD初学指南
去年就打算总结一下,结果新换的工作特别忙,就迟迟没有认真动手.主要内容是很多初学DDD甚至于学习很长时间的同学没有弄明白DDD是什么,适合什么情况.这世界上没有银弹,抛开了适合的场景孤立的去研究DDD ...
- UIViewController生命周期-完整版
一.UIViewController 的生命周期 下面带 (NSObject)的方法是NSObject提供的方法.其他的都是UIViewController 提供的方法. load (NSObje ...
- javascript 判断参数类型大全
js 判断类型的在开发中是很常用的,因为js 是弱类型的语言,var 可以接受任何形式的类型,但是在真正的开发中,我们需要根据不同类型做不同的处理,所以这个是必须的精通. 首先需要知道 typeof这 ...
- C++随笔:.NET CoreCLR之corleCLR核心探索之coreconsole(1)
一看这个标题,是不去取名有点绕呢?或者是,还有些问题?报告LZ...你的标题取得有问题,是个病句!↖(^ω^)↗!!!先不要急,其实我今天带给大家的就是CoreCLR中的coreclr.其中它是在名字 ...
- js学习之类型识别
用来判别类型的方法有好多,整理了一下4种方法,平时用的时候,在不同情景下,还是要结合着使用的. 方法一 typeof:可以识别标准类型,除了Null:不能识别具体的对象类型,除了Function &l ...
- 反应器(Reactor)和主动器(Proactor)
网络方面用的比较多的库是libevent和boost.asio,两者都是跨平台的.其中libevent是基于Reactor实现的,而boost.asio是基于Proactor实现的.Reactor和P ...
- join Linq
List<Publisher> Publishers = new List<Publisher>(); Publisher publish1 = new Publisher() ...
- Dancing Links and Exact Cover
1. Exact Cover Problem DLX是用来解决精确覆盖问题行之有效的算法. 在讲解DLX之前,我们先了解一下什么是精确覆盖问题(Exact Cover Problem)? 1.1 Po ...