Page cover

What's Queue & Implementation?

The Queue class is a container adaptor that gives the programmer the functionality of a queue - specifically, a FIFO (first-in, first-out) data structure.

Implementation Using STL
#include <iostream>
#include <queue>

using namespace std;

// Print the queue
void showq(queue<int> q)
{
	while (!q.empty()) {
		cout << '\t' << q.front();
		q.pop();
	}
	cout << '\n';
}

// Driver Code
int main()
{
	queue<int> q;
	q.push(10);
	q.push(20);
	q.push(30);

	cout << "The queue q is : ";
	showq(q);

	cout << "\nq.size() : " << q.size();
	cout << "\nq.front() : " << q.front();
	cout << "\nq.back() : " << q.back();

	cout << "\nq.pop() : ";
	q.pop();
	showq(q);

	return 0;
}

Last updated

Was this helpful?