![]() |
In C++, the Standard Template Library (STL) provides a map container to store elements in a mapped fashion so each element has a key value and a mapped value. In this article, we will see how to find the maximum key in a map in C++. Example: Input : Finding the Biggest Key in a Map in C++To find the maximum key in a map, we can use the std::map::rbegin() function that returns a reverse iterator pointing to the last element in the map, which is the maximum key because the map in C++ is in increasing order of keys by default. C++ Program to Find the Largest Key in a MapThe below example demonstrates how we can use the rbegin() function of a map to find the maximum key in a map in C++ STL. C++
Output
Maximum key in the map: 4 Time Complexity: O(1), where N is the size of the map.
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |