跳到主要内容

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容器允许从一端新增元素,从另一端移除元素。

注意

只有queue的顶端元素,才有机会被外界去用。queue不提供遍历功能,也不提供迭代器。

  1. empty
  2. size
  3. front,
  4. back
  5. push_back
  6. pop_front
member functiondefinition
(constructor)Construct queue
emptyTest whether container is empty
sizeReturn size
frontAccess next element
backAccess last element
pushInsert element
emplaceConstruct and insert element
popRemove next element
swapSwap 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(); // 返回队列的大小
Loading Comments...