![]() |
In C++, a map is a container provided by the STL library that stores data in key-value pairs in an ordered or sorted manner. In this article, we will learn how to find the last key-value pair in a Map in C++. Example: Input: Find Last Key in a std::map in C++To find the last key-value pair in a std::map, we can use the std::map::end() function which returns an iterator pointing to the imaginary element after the last element of the map container with a combination of std::prev() to get access to the last key-value pair in the map. C++ Program to Find the Last Key-Value Pair in a MapThe below example demonstrates how we can find the last key-value pair in a map in C++ STL. C++
Output
Last Key-Value pair in the Map is : {4, JavaScript} Time Complexity: O(1) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |