How to Create a Deque of Maps in C++? Last Updated : 26 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report 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++: C++ // C++ Program to illustrate how to create a deque of maps #include <deque> #include <iostream> #include <map> using namespace std; int main() { // Initialize a deque of maps deque<map<int, string> > dq; // Initialize maps with few entries map<int, string> mp1; mp1[1] = "C++"; mp1[2] = "Java"; map<int, string> mp2; mp2[1] = "JavaScript"; mp2[2] = "Python"; // Insert the maps to the deque dq.push_back(mp1); dq.push_back(mp2); // Print the deque of maps cout << "Deque Elements: " << endl; int i = 1; for (auto it = dq.begin(); it != dq.end(); ++it) { cout << "Map" << i << " { "; for (auto p : *it) { cout << "{" << p.first << ", " << p.second << "} "; } i++; cout << " }" << endl; } return 0; } OutputDeque 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 More infoAdvertise with us Next Article How to Create Deque of Multimap in C++? R rohitpant4532 Follow Improve Article Tags : C++ Programs C++ STL cpp-map cpp-deque CPP Examples +2 More Practice Tags : CPPSTL Similar Reads How to Create Deque of Multimap in C++? In C++, a deque (double-ended queue) is a data structure that allows insertion and deletion at both ends, while a multimap is an associative container that contains key-value pairs, where multiple keys can have the same value. In this article, we will learn how to create a deque of multimaps in C++ 2 min read How to Create Deque of Multiset in C++? In C++, deques are containers that allow efficient insertion and deletion operations from both ends. Multisets are associative containers similar to sets but unlike sets, multisets allow duplicate insertions as well. In this article, we will learn how to create a deque of multiset in C++. Example In 2 min read How to Create a Deque of Sets in C++? In C++, a container called deque is a queue like container but allows for fast insertions and deletions at both ends. In this article, we will learn how to create a deque of sets in C++. Example: Input: mySet1 = {1, 4, 8, 9, 11} mySet2 = {1, 2, 3, 5, 7} Output: myDeque: [ {1, 4, 8, 9, 11}, {1, 2, 3, 2 min read How to Create a Stack of Deque in C++? In C++, the stack is a container in which new elements are added from one end (top) and removed from that end only whereas a deque (double-ended queue) are sequence container with the feature of expansion and contraction on both ends. In this article, we will learn how to create a stack of deque in 2 min read How to Create a Deque of Arrays in C++? In C++, a deque (double-ended queue) is a data structure that allows insertion and deletion at both ends whereas arrays are fixed-size collections of elements. In this article, we will learn how to create a deque of arrays in C++ STL. Example: Input: myArray1 = {1, 4, 8, 9, 11} myArray2 = {1, 2, 3, 2 min read How to Create a Deque of Vectors in C++? In C++, deques are sequence containers similar to queues but unlike queues, deques allow the insertion and deletion of elements from both ends efficiently. Vectors are dynamic arrays that can resize themselves during the runtime. In this article, we will learn how to create a deque of vectors in C++ 2 min read Like