![]() |
In C++, maps are associative containers provided by the STL library of C++, that allow the users to store data in key-value pairs where the keys must be unique. In this article, we will learn how to create a map of maps in C++. For Example, Input: myMap1={1, "C++"}; myMap2={1, "Java"}; myMap3={2, "Python"}; Output: Map Elements: { {1: {1, "C++"} }, {2: {1, "Java"} }, {3: {2, "Python"} } Map of Maps in C++To create a std::map of maps first, we need to declare a map where the key is of the desired type and the value is of the type map. We can do that by passing the value template parameter as a map. Syntax to Declare Map of Mapsmap < keytype, map <innerKeyType, valueType> > myMap
C++ Program to Create a Map of MapsThe below program demonstrates how we can create a map of maps in C++ STL. C++
Output
Map of maps: 1, 1 => one 1, 2 => two 2, 1 => two 2, 2 => four Time Complexity: O(N * M log(N*M) ), here N is the number of maps in the map and M is the average size of the inner maps |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |