![]() |
In C++, an unordered multimap container stores key-value pairs in no particular order. Unlike a map, an unordered multimap allows multiple values to be associated with a single key. In this article, we will learn how to create an unordered multimap of tuples in C++. For Example, Input: myPair1 = { "apple", make_tuple(1, "red") } myPair2 = { "banana", make_tuple(2, "yellow") } Output: unordered_Multimap: apple 1 red banana 2 yellow Create an Unordered Multimap of Tuples in C++To create an unordered multimap where tuples are values, we will have to define the type of the key during the declaration. After that, we can insert the elements using make_pair() with the unordered_multimap::insert() function. Syntax to Declare Unordered Multimap of Tuplesmultimap<keyType, tuple<dataType1, dataType2, dataType3,...> > multimapName;
C++ Program to Create an Unordered Multimap of TuplesThe below example demonstrates how we can create an unordered multimap of tuples in C++ STL. C++
Output Unordered Multimap: cherry 3 red banana 2 yellow apple 1 red Time Complexity: O(N), here N is the number of tuples. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |