![]() |
VOOZH | about |
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"} ]
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:
deque<map<KeyType, ValueType>> deque_Name;
The following program illustrates how to create a deque of maps in C++:
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.