Cpp Standard Library 简明教程

C++ Library - <queue>

Introduction to queue

队列是一种旨在在 FIFO(先进先出)环境中操作的数据结构。在队列中,元素从后端插入并从前端移除。

Queue is a data structure designed to operate in FIFO (First in First out) context. In queue elements are inserted from rear end and get removed from front end.

队列类是一种容器适配器。容器是一种保存相同类型数据的对象。队列可以从不同的序列容器中创建。容器适配器不支持迭代器,因此我们不能使用它们进行数据操作。然而,它们支持 push() 和 pop() 成员函数分别用于数据插入和删除。

Queue class is container adapter. Container is an objects that hold data of same type. Queue can be created from different sequence containers. Container adapters do not support iterators therefore we cannot use them for data manipulation. However they support push() and pop() member functions for data insertion and deletion respectively.

Definition

以下是来自头文件 <queue> 的 std::queuer 的定义

Below is definition of std::queuer from <queue> header file

template <class T, class Container = deque<T> > class queue;

Parameters

  1. T − Type of the element contained. T may be substituted by any other data type including user-defined type.

  2. Container − Type of the underlying container object.

Member types

以下成员类型可作为参数或返回类型,由成员函数使用。

Following member types can be used as parameters or return type by member functions.

Functions from <queue>

以下是来自头文件 <queue> 的所有方法的列表。

Below is list of all methods from <queue> header.

Constructors

Destructor

Member functions

Non-member overloaded functions