Queue C++

Queue is a type of container adapter specially designed to work in first in first out context. In queue the element is inserted at the back-end and removed from front-end. For working on FIFO context queues are mainly used.

Basic Functions

Following are basic functions used with Queue:

FunctionDescription
empty()Returns true if queue is empty
size()Returns the size of queue
push(g)Inserts element at the end of queue
pop()Removes element from the front of queue
queue::swap() in C++ STL
queue::swap() in C++ STLIt will exchange contents of queue only if queue type is same. If there is difference in size then its ok
queue::front() in C++ STLReturns reference of first element in queue
queue::back() in C++ STLReturns reference of last element in queue

Example

Following is an example for C++ queue:

The output should be:

Display queue qfirst :
5 10 15 20 25

Queue Size qfirst.size() : 5
Element at front qfirst.front() : 5
Element at back qfirst.back() : 25Displaying queue before pop() operation :
5 10 15 20 25

qfirst.pop()

Displaying queue after pop() operation :
10 15 20 25

LEAVE A REPLY

Please enter your comment!
Please enter your name here