![]() |
In C++, multimap can store multiple values for a single key, and the elements are stored in an order of lowest to highest key value. In this article, we will discuss how to search for an element in a multimap in reverse order in C++ Example Input: multimapp={{ 1, "One" }, { 2, "Two" }, { 1, "Second One" }, { 3, "Three" }, { 2, "Second Two" }} ; keyToSearch=2 Output: Found:2-> Second Two Searching Multimap in Reverse Order in C++To search multimap in reverse order for an element associated with some key, we can use the std::multimap::equal_range() which will return the pair of iterators where one points to the first element with the given key and the other points to the last element with the given key. C++ Program for Searching Multimap in Reverse OrderThe below example demonstrates the searching of multimap in reverse order using reverse iterators. C++
Output
Key: 1 Value: 500 Time Complexity: O(logN) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |