CPP Queue

Queue is a data structure in CPP that works on FIFO (First In First Out) technique, which means that the first inserted element will be deleted first in a queue.


template<class T, class Container = deque<T> > class queue;

Member Types of CPP Queue:

container_typeTo specify underlying container type.
const_referenceTo specify the reference type of constant container.
size_typeTo specify the size range of the elements.
value_typeTo specify the element type.
referenceTo specify the reference type of container.


CPP Queue Functions:

backTo access the rear element of the queue.
(constructor)To construct a queue container.
emptyTo test for the emptiness of a queue and to get a true value if the queue is empty.
emplaceTo insert a new element in the queue above the current rear end element.
frontTo access the front element of the queue.
pushTo insert a new element at the rear end of the queue.
popTo delete the element in the queue from the front end.
swapTo interchange the contents of two containers in reference.
sizeTo return the size of the queue container, which is a measure of the number of elements stored in the queue.



#include <iostream.h>  
#include <queue.h>  
using namespace std;  
void display(queue <int> ds)  
queue <int> dis = ds;  
while (!dis.empty())  
	cout << dis.front() << " ";  
int main()  
queue <int> getqueue;  
cout << "The Queue element from first to last are  : ";  
cout << "\nThe value of getqueue.size() : " << getqueue.size();  
cout << "\nThe value of getqueue.front() : " << getqueue.front();  
cout << "\nThe value of getqueue.back() : " << getqueue.back();  
cout << "\nThe value of getqueue.pop() : ";  
return 0;  


The Queue element from first to last are : 80 60 50 30                                          
The value of getqueue.size() : 4                      
The value of getqueue.front() : 80                    
The value of getqueue.back() : 30   
The value of getqueue.pop() : 60 50 30
Content Protection by DMCA.com
Please Share