Double Ended Queue

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

int main() {

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

	/* Enqueue data into the front of queue */
	data.push_front(20);
	data.push_front(10);

	/* Enqueue data into the back of queue */
	data.push_back(30);
	data.push_back(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 front of queue */
	data.pop_front();

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

	/* Dequeue data from the back of queue */
	data.pop_back();

	cout << "Queue size after dequeue from back: " << 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 from front: 3
Now top data on queue: 20
Now bottom data on queue: 40
Queue size after dequeue from back: 2
Now top data on queue: 20
Now bottom data on queue: 30

Comments (0)

  • To add your comment please or

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

Got It!