C++ <queue>
A queue is a linear dynamic data structure that follows First-In/First-Out (FIFO) principle. In a queue, addition of a new element and deletion of an element occurs at different end which implies that the element which is added first in the queue will be the first to be removed from the queue.
Features of queue
- It is a dynamic data structure.
- It has dynamic size.
- It uses dynamic memory allocation.
Syntax
template < class T, class Container = deque<T> > class queue;
Parameters
T |
Type of the elements stored in the container. |
Container |
Type of the underlying container object where the elements are stored. |
Member Types
Member types | Definition |
value_type | T (First template parameter) |
container_type | Container (Second template parameter), deque<value_type> |
reference | value_type& |
const_reference | const value_type& |
size_type | size_t |
The C++ queue container has a number of member functions which are listed below:
Functions | Description |
empty() |
Checks whether the queue is empty or not. |
size() |
Returns the length of the queue in terms of bytes. |
front() |
Access first element of the queue. |
back() |
Access last element of the queue. |
pop() |
Deletes first element of the queue. |
push() |
Adds a new element at the end of the queue. |
emplace() |
Constructs and inserts a new element at the end of the queue, after its current last element. |
swap() |
Exchanges elements between two queues. |
Functions | Description |
operator == |
Checks whether two queues are equal or not. |
operator != |
Checks whether two queues are unequal or not. |
operator < |
Checks whether the first queue is less than the other or not. |
operator > |
Checks whether the first queue is greater than the other or not. |
operator <= |
Checks whether the first queue is less than or equal to the other or not. |
operator >= |
Checks whether the first queue is greater than or equal to the other or not. |
swap() |
Exchanges elements between two queues. |