The set::crbegin() is a built-in function in C++ STL which returns a constant iterator pointing to the last element in the container. The iterator cannot be used to modify the elements in the set container. The iterators can be increased or decreased to traverse the set accordingly.
Syntax:
constant_iterator set_name.crbegin()
Parameters: The function does not take any parameter.
Return value: The function returns a constant iterator pointing to the last element in the container.
Program to demonstrate the set::crbegin() method:
CPP
// CPP program to demonstrate the // set::crbegin() function #include <bits/stdc++.h> using namespace std; int main() { int arr[] = { 14, 12, 15, 11, 10 }; // initializes the set from an array set< int > s(arr, arr + 5); // prints all elements in set for ( auto it = s.crbegin(); it != s.crend(); it++) cout << *it << " " ; return 0; } |
15 14 12 11 10
The set::crend() is a built-in function in C++ STL which returns a constant iterator pointing to the position just before the first element in the container. The iterator cannot be used to modify the elements in the set container. The iterators can be increased or decreased to traverse the set accordingly.
Syntax:
constant_iterator set_name.crend()
Parameters: The function does not take any parameter.
Return value: The function returns a constant iterator pointing to the position just before the first element in the set container.
Program to demonstrate the set::crend() method:
CPP
// CPP program to demonstrate the // set::crend() function #include <bits/stdc++.h> using namespace std; int main() { int arr[] = { 14, 12, 15, 11, 10 }; // initializes the set from an array set< int > s(arr, arr + 5); // prints all elements in set for ( auto it = s.crbegin(); it != s.crend(); it++) cout << *it << " " ; return 0; } |
15 14 12 11 10