Sun Dec 22 2019

Queue

C++ Programming1538 views

File Name: queue.cpp

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

int main() {

	/* Create a queue */
	queue<int> data;

	/* Enqueue data into the queue */
	data.push(10);
	data.push(20);
	data.push(30);
	data.push(40);
	
	cout << "Queue size: " << data.size() << endl;
	cout << "Data on top of the queue: " << data.front() << endl;
	cout << "Data on bottom of the queue: " << data.back() << endl;

	/* Dequeue data from the queue */
	data.pop();

	cout << "Queue size after dequeue: " << data.size() << endl;
	cout << "Now top data on queue: " << data.front() << endl;
	cout << "Now bottom data on queue: " << data.back() << endl;
	
	return 0;
}


/* Output */
Queue size: 4
Data on top of the queue: 10
Data on bottom of the queue: 40
Queue size after dequeue: 3
Now top data on queue: 20
Now bottom data on queue: 40

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.