![]() |
In C++, sets are a type of associative container in which each element has to be unique because the value of the element identifies it. The values are stored in a specific sorted order i.e. either ascending or descending. In this article, we will learn how to find the last element in a set in C++. Example: Input: Finding the Last Element in a Set in C++To find the last element in a std::set in C++, we can use the std::set::rbegin() function that returns a reverse iterator pointing to the last element of the set. We can then dereference this iterator to find the last element. C++ Program to Find the Last Element in a SetC++
Output
Last element is: 8 Time complexity :O(1) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |