C++ Program to implement queue using standard template library (STL)

By | 03.03.2017

C++ Program to implement queue using STL


Write a C++ Program to implement queue using standard template library (STL). Here’s simple Program to implement queue using standard template library (STL) in C++ Programming Language.


  • Queue is a first-in, first-out (FIFO) data structure. i.e. the element added first to the queue will be the one to be removed first.
  • Elements are always added to the back of the queue and removed from the front of the queue.
  • ADD/ PUSH refers to adding an element to the queue while DELETE/ POP refers to removing an element from the queue.
  • This C++ Program demonstrates implementation of Queue in STL.

Below is the source code for C++ Program to implement queue using standard template library (STL) which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


/*  C++ Program to implement queue using standard template library (STL)  */

#include <iostream>
#include <queue>
using namespace std;

int main()
{
   queue<int> q;
   q.push(1);
   q.push(2);
   q.push(3);
   q.push(4);
    q.push(5);

   cout << "Size of the queue: " << q.size() << endl;

   cout << q.front() << endl;
   q.pop();

   cout << q.front() << endl;
   q.pop();

   cout << q.front() << endl;
   q.pop();

   cout << q.front() << endl;
   q.pop();

   cout << q.front() << endl;
   q.pop();
   
   if ( q.empty() ) {
   cout << "Queue is empty" << endl;
   }
}

Related Post : : Write a C Program to Implement a Queue using an Array


OUTPUT : :


/*  C++ Program to implement queue using standard template library (STL)  */

Size of the queue: 5
1
2
3
4
5
Queue is empty

Above is the source code and output for C++ Program to implement queue using standard template library which is successfully compiled and run on Windows System to produce desired output.

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.


Thanks for reading the post….

5 1 vote
Article Rating
Category: C++ Programming Data Structures Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments