Check out example codes for "how to access last element of set in c++". It will help you in understanding the concepts better.

Code Example 1

set<int> s = {1,2,3}
auto it = s.end();
it--;
cout<<*it<<"\n"; // This refers to last element of a set

Code Example 2

// C++ program to delete last element 
// of a Set by passing its iterator 
  
#include <iostream> 
#include <set> 
using namespace std; 
  
// Function to print the set 
void printSet(set<int> myset) 
{ 
  
    // Get the iterator 
    set<int>::iterator it; 
  
    // printing all the elements of the set 
    for (it = myset.begin(); it != myset.end(); ++it) 
        cout << ' ' << *it; 
    cout << '\n'; 
} 
  
// Function to delete last element of set 
// using method 1 
void deleteByMethod1(set<int> myset) 
{ 
  
    // printing all the elements of the set 
    cout << "\nSet originally: "; 
    printSet(myset); 
  
    // Get the iterator 
    set<int>::iterator it; 
  
    // Get the positionOfElementToBeDeleted 
    // using method 1 
    it = prev(myset.end()); 
  
    // Erase the last element 
    // currently pointed by the iterator 
    myset.erase(it); 
  
    // printing all the elements of the set 
    cout << "Set after deletion: "; 
    printSet(myset); 
} 
  
// Driver code 
int main() 
{ 
    set<int> myset; 
  
    // Get the set 
    for (int i = 1; i < 10; i++) 
        myset.insert(i * 10); 
  
    // Method 1 to get positionOfElementToBeDeleted 
    deleteByMethod1(myset); 
  
    return 0; 
}

Learn ReactJs, React Native from akashmittal.com