![]() |
In C++ multimap is a container to store key-value pairs allowing duplicate keys which is not allowed in a map container. By default, the multimap container uses the less than ‘<‘ operator to compare the keys for ordering the entries but also allows the use of the custom comparator. In this article, we will learn how to use a multimap with a custom comparator in C++. Custom Comparator for Multimap in C++To use a std::multimap with a custom comparator, we can define a comparison function or a functor (a class that overloads the C++ Program to Use a Multimap with a Custom ComparatorThe below example demonstrates how we can use a multimap with a custom comparator in C++. C++
Output
Multimap using custom comparator kiwi: 2 apple: 5 apple: 10 banana: 3 orange: 4 Time Complexity: O(N log N), here N is the number of elements in a multimap. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |