FIFO ( First | C ++ program to demonstrate working of FIFO using Queue interface in C ++ ; print the elements of queue ; Driver code ; Adds elements { 0 , 1 , 2 , 3 , 4 } to queue ; Display contents of the queue . ; To remove the head of queue . In this the oldest element '0' will be removed ; To view the head of queue ; Rest all methods of collection interface , Like size and contains can be used with this implementation .
#include <bits/stdc++.h> NEW_LINE using namespace std ; void print_queue ( queue < int > q ) { while ( ! q . empty ( ) ) { cout << q . front ( ) << " ▁ " ; q . pop ( ) ; } cout << endl ; } int main ( ) { queue < int > q ; for ( int i = 0 ; i < 5 ; i ++ ) q . push ( i ) ; cout << " Elements ▁ of ▁ queue - " ; print_queue ( q ) ; int removedele = q . front ( ) ; q . pop ( ) ; cout << " removed ▁ element - " << removedele << endl ; print_queue ( q ) ; int head = q . front ( ) ; cout << " head ▁ of ▁ queue - " << head << endl ; int size = q . size ( ) ; cout << " Size ▁ of ▁ queue - " << size ; return 0 ; }