queue<T, Sequence>

Categories: containers, adaptors

Component type: type

Description

A queue is an adaptor that provides a restricted subset of Container functionality A queue is a 'first in first out' (FIFO) data structure. [1] That is, elements are added to the back of the queue and may be removed from the front; Q.front() is the element that was added to the queue least recently. Queue does not allow iteration through its elements. [2]

Queue is a container adaptor, meaning that it is implemented on top of some underlying container type. By default that underlying type is deque, but a different type may be selected explicitly.

Example

int main() {

 queue<int> Q;

 Q.push(8);

 Q.push(7);

 Q.push(6);

 Q.push(2);

 assert(Q.size() == 4);

 assert(Q.back() == 2);

 assert(Q.front() == 8);

 Q.pop();

 assert(Q.front() == 7);

 Q.pop();

 assert(Q.front() == 6);

 Q.pop();

 assert(Q.front() == 2);

 Q.pop();

 assert(Q.empty());

}

Definition

Defined in the standard header queue, and in the nonstandard backward-compatibility header stack.h.

Template parameters
Parameter Description Default
T The type of object stored in the queue.
Sequence The type of the underlying container used to implement the queue. deque<T>
Model of

Assignable, Default Constructible

Type requirements

• T is a model of Assignable.

• Sequence is a model of Front Insertion Sequence.

• Sequence is a model of Back Insertion Sequence.

• Sequence::value_type is the same type as T.

• If operator== is used, then T is a model of Equality Comparable

• If operator< is used, then T is a model of LessThan Comparable.

Public base classes

None.

Members
Member Where defined Description
value_type queue See below.
size_type queue See below.
queue() Default Constructible The default constructor. Creates an empty queue.
queue(const queue&) Assignable The copy constructor.
queue& operator=(const queue&) Assignable The assignment operator.
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату