---
title: "Double Ended Queue"
description: "Learn c plus plus by example of double ended queue"
url: "https://www.geekboots.com/cpp/deque"
markdown_url: "https://www.geekboots.com/cpp/deque/md"
category: "C++ Programming"
author: "Geekboots"
published: "2016-06-06"
updated: "2026-11-28T21:24:09.769Z"
tags: ["cpp", "c plus plus", "deque", "double ended queue"]
---

# Double Ended Queue (C++ Programming)

> Learn c plus plus by example of double ended queue

## Source Code

### deque.cpp

```cpp
#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
```

## Related Code Examples

- [STL Min Max](https://www.geekboots.com/cpp/stl-min-max) ([Markdown](https://www.geekboots.com/cpp/stl-min-max/md))
- [Multimap](https://www.geekboots.com/cpp/multimap) ([Markdown](https://www.geekboots.com/cpp/multimap/md))
- [Map](https://www.geekboots.com/cpp/map) ([Markdown](https://www.geekboots.com/cpp/map/md))
- [Binary Tree](https://www.geekboots.com/cpp/binary-tree) ([Markdown](https://www.geekboots.com/cpp/binary-tree/md))
- [Queue](https://www.geekboots.com/cpp/queue) ([Markdown](https://www.geekboots.com/cpp/queue/md))
- [Stack](https://www.geekboots.com/cpp/stack) ([Markdown](https://www.geekboots.com/cpp/stack/md))
- [Doubly Linked list](https://www.geekboots.com/cpp/doubly-linkedlist) ([Markdown](https://www.geekboots.com/cpp/doubly-linkedlist/md))
- [Singly Linked list](https://www.geekboots.com/cpp/singly-linkedlist) ([Markdown](https://www.geekboots.com/cpp/singly-linkedlist/md))

---
Source: [Geekboots](https://www.geekboots.com/cpp/deque)
