VOOZH about

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

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


  • Courses
  • Tutorials
  • Interview Prep

How to Create Deque of Multimap in C++?

Last Updated : 23 Jul, 2025

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"} } ]

Creating Deque of Multimap in C++

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.

Syntax to Create a Deque of Multimaps in C++

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.

C++ Program to Create Deque of Multimap

The below example demonstrates how we can create a deque of multimaps in C++.


Output
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)



Comment