(Translated by https://www.hiragana.jp/)
Deque Data Structure - GeeksforGeeks
Open In App

Deque Data Structure

Last Updated : 30 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Deque or Double Ended Queue is a generalized version of Queue data structure that allows insert and delete at both ends. Below is an example program of deque in different languages.

Deque
  • Deque can act as both Stack and Queue
  • It is useful in many problems where we need to have a subset of all operations also like insert/remove at front and insert/remove at the end.
  • It is typically implemented either using a doubly linked list or circular array.

Implementations in Different Languages

Below are example programs in different languages.

C++
#include <iostream>
#include <deque>

using namespace std;

int main() {
    deque<int> dq;

    dq.push_back(10);
    dq.push_back(20);
    dq.push_front(30);

    // Print deque elements
    for (int x : dq) cout << x << " ";
    cout << endl;

    // Pop from front and back
    dq.pop_front();
    dq.pop_back();

    // Print deque elements after pop
    for (int x : dq) cout << x << " ";
    
    return 0;
}
Java Python C#

Basics

Easy Problems

Medium Problems


Deque Introduction
Visit Course explore course icon
Video Thumbnail

Deque Introduction

Video Thumbnail

Deque Applications

Article Tags :
Practice Tags :

Similar Reads