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: queue 是一种先进先出(First In First Out, FIFO)的数据结构,它有两个出口,queue容器允许从一端新增元素,从另一端移除元素。
- empty
- size
- front,
- back
- push_back
- pop_front
| member function | definition |
|---|---|
| (constructor) | Construct queue |
| empty | Test whether container is empty |
| size | Return size |
| front | Access next element |
| back | Access last element |
| push | Insert element |
| emplace | Construct and insert element |
| pop | Remove next element |
| swap | Swap contents |
构造函数
赋值
queue<T> queT; // queue对象的默认构造函数形式,采用模版类实现
queue(const queue& que); // 拷贝构造函数
queue& operator=(const queue& que); // 重载赋值操作符
存取
void push(T elem); // 往队尾添加元素
void pop(); // 从队头移除第一个元素
T& back(); // 返回最后一个元素
T& front(); // 返回第一个元素
大小操作
bool empty(); // 判断队列是否为空
int size(); // 返回队列的大小