![]() |
VOOZH | about |
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++ STL.
Example:
Input: myMultimap1 = { {1, "apple"}, {2, "banana"}, {1, "mango"} } myMultimap2 = { {3, "grapes"}, {4, "orange"}, {3, "kiwi"} } Output: myDeque: [ { {1, "apple"}, {2, "banana"}, {1, "mango"} }, { {3, "grapes"}, {4, "orange"}, {3, "kiwi"} } ]
To create a std::deque of std::multimap in C++, we can pass the type of the deque container to be of the type std::multimap as a template parameter while declaration.
deque<multimap<dataType1, dataType2>> dequeName;Here,
dataType1 denotes the data type of the key stored in the multimap.dataType2 denotes the data type of the value stored in the multimap.dequeName is a name of deque of multimaps.The below example demonstrates how we can create a deque of multimaps in C++.
myDeque:
Multimap1: {1, apple} {2, banana}
Multimap2: {3, orange} {4, grape}
Time Complexity: O(N * M), where N is the number of maps and M is the average size of each map.
Auxilliary Space: O(N * M)