VOOZH about

URL: https://www.geeksforgeeks.org/cpp/deque-of-maps-in-cpp/

⇱ How to Create a Deque of Maps in C++? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Create a Deque of Maps in C++?

Last Updated : 23 Jul, 2025

In C++, the Standard Template Library (STL) provides a container called deque that allows efficient insertion and deletion operations at both ends of the container. A map is an associative container that stores elements in key-value pairs.In this article, we will learn how to create a deque of maps in C++.

Example

Input:
myMap1: {1: "C++", 2: "Python"}
myMap2: {1: "Java", 3: "Javascript"}

Output:
myDeque: [ {1: "C++", 2: "Python"},
 {1: "Java", 3: "Javascript"} ]

Create a Deque of Maps in C++

To create a std::deque of std::maps in C++, we have to define the type of the deque element as std::map in the deque declaration as shown in the below syntax:

Syntax to Create a Deque of Maps in C++

deque<map<KeyType, ValueType>> deque_Name;

C++ Program to Create a Deque of Maps

The following program illustrates how to create a deque of maps in C++:


Output
Deque Elements: 
Map1 { {1, C++} {2, Java} }
Map2 { {1, JavaScript} {2, Python} }

Time Complexity: O(N*M)where N is the number of elements in the map.
Auxiliary Space: O(N*M), where M is the average number of key-value pairs in map.



Comment