set crend() in C++

crend(): This function is a build-in function in STL. This function returns a 

read-only (constant) reverse iterator that points to the last pair in the set.

Note: Iteration is done in descending order according to the keys. 

This function is available in the below file.

File: stl_set.h

Parameters: No parameters are required for this function.

Syntax:

set<data_type>:: reverse_iterator it  = st.crend()

For Example:

st = {1,2,3,4}

st.crend() = > It points to the last element (i.e 4) in the set.

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    set<intst;
    st.insert(4);
    st.insert(2);
    st.insert(3);
    st.insert(1);

    set<int>::reverse_iterator it = st.crend();

    cout << *it << "\n";

    return 0;
}


No comments:

Post a Comment