C++ std::queue

时间:2022-09-24 08:55:46

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

cplusplus


C++ std::queue的更多相关文章

  1. 从deque到std&colon;&colon;stack,std&colon;&colon;queue,再到iOS 中NSArray(CFArray)

    从deque到std::stack,std::queue,再到iOS 中NSArray(CFArray) deque deque双端队列,分段连续空间数据结构,由中控的map(与其说map,不如说是数 ...

  2. C&plus;&plus;11&colon;基于std&colon;&colon;queue和std&colon;&colon;mutex构建一个线程安全的队列

    C++11:基于std::queue和std::mutex构建一个线程安全的队列 C++中的模板std::queue提供了一个队列容器,但这个容器并不是线程安全的,如果在多线程环境下使用队列,它是不能 ...

  3. 问题解决——在STL的queue中使用自定义类

    本文原创,转载请保证文章的完整性,并显要的注明出处. 本文链接:http://blog.csdn.net/wlsgzl/article/details/38843513 平时很少用STL,就算用,也基 ...

  4. 容器适配器之queue

    转载http://blog.csdn.net/thefutureisour/article/details/7751846容器适配器容器适配器其实就是一个接口转换装置,使得我们能用特定的方法去操作一些 ...

  5. leetcode:Implement Stack using Queues 与 Implement Queue using Stacks

    一.Implement Stack using Queues Implement the following operations of a stack using queues. push(x) - ...

  6. uva 12100 Printer Queue

    The only printer in the computer science students' union is experiencing an extremely heavy workload ...

  7. uva 10935 throwing cards away &lt&semi;queue&gt&semi;

    Given is an ordered deck of    n    cards numbered 1 to    n    with card 1 at the top and card    n ...

  8. &num;include &lt&semi;queue&gt&semi;

    双端队列deque比向量vector更有优势 双端队列(deque) 连续存储的指向不同元素的指针所组成的数组<deque> 队列(queue) 先进先出的值的排列 <queue&g ...

  9. C&plus;&plus;标准库之queue(各函数及其使用全)

    原创作品,转载请注明出处:http://www.cnblogs.com/shrimp-can/p/5283520.html 一.FIFO队列,即先入先出队列 1.队列的声明 std::deque&lt ...

随机推荐

  1. Acer-宏碁电脑BOIS

    进入电脑BOIS界面; 1.开机(一闪而过)注意第一屏左下角,会有进入BIOS按键提示. 2.如一开机没有进入BIOS的键值提示,取而代之的是品牌机的Logo,可参阅以下列表:不是品牌机可参阅主板设置 ...

  2. 使用gogs&comma;drone搭建自动部署

    使用gogs,drone搭建自动部署 使用gogs,drone,docker搭建自动部署测试环境 Gogs是一个使用go语言开发的自助git服务,支持所有平台Docker是使用go开发的开源容器引擎D ...

  3. websocket nova vnc proxy

    1. vnc proxy的实现原理 vnc 是nova提供的用来访问虚拟机的一项重要功能,用户可以通过websocket来访问,也可以通过java客户端来访问.通过websket访问虚拟机 的功能已经 ...

  4. VR全景智慧城市--2017年VR项目加盟将是一个机遇

    全景智慧城市项目是河南艺境空间文化传播有限公司自主开发的国内第一家商业全景平台, 旨在构建全景城市,实现智慧生活,让人们随时随地身临其境拥有全世界,享受快捷.真实.趣味.优质生活. 以VR虚拟现实技术 ...

  5. JAVA HashMap 解析

    1.简介(其实是HashMap注释的大致翻译) 本文基于JDK1.8,与JDK1.7中的HashMap有一些区别,看官注意区别. HashMap实现了Map接口,提供了高效的Key-Value访问.H ...

  6. document&lowbar;index&lowbar;data&period;go

    package types type DocumentIndexData struct {     // 文档全文(必须是UTF-8格式),用于生成待索引的关键词     Content string ...

  7. NLP入门(四)命名实体识别(NER)

      本文将会简单介绍自然语言处理(NLP)中的命名实体识别(NER).   命名实体识别(Named Entity Recognition,简称NER)是信息提取.问答系统.句法分析.机器翻译等应用领 ...

  8. 自动化测试基础篇--Selenium单选框(Radio)复选框(CheckBox)

    摘自:https://www.cnblogs.com/sanzangTst/p/7686602.html 一.什么是单选框.复选框? 二.单选框:radio 三.复选框:checkbox 四.判断是否 ...

  9. SolidWorks基础-快速入门

    SolidWorks 介绍 SolidWorks 是一款机械设计自动化软件包 用于设计与分析机械结构 SolidWorks主要是工程师表达自己思想的工具 学习 SolidWorks 的方法 找一个基础 ...

  10. python学习之路05

    控制流语句 博主认为所有的语言中,控制语句都是差不多的,无非就是循环,判断,if ,while,for.更重要的是,多加的练习,实战中发现自身问题,加深巩固 所以,下面会以实际的题目为主. 1.用户在 ...