multiset rbegin() and rend() function in C++ STL
Last Updated :
12 Jun, 2023
multiset::rbegin() is a built-in function in C++ STL which returns a reverse iterator pointing to the last element in the multiset container.
Syntax:
reverse_iterator multiset_name.rbegin()
Parameters: The function does not take any parameter.
Return value: The function returns a reverse iterator pointing to the last element in the container.
Below program illustrate the multiset::rbegin() method:
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr[] = { 15, 12, 15, 11, 10, 10 };
multiset< int > s(arr, arr + 6);
multiset< int >::reverse_iterator rit;
for (rit = s.rbegin(); rit != s.rend(); rit++)
cout << *rit << " ";
cout << "\nThe last element in multiset is " << *(s.rbegin());
return 0;
}
|
Output:
15 15 12 11 10 10
The last element in multiset is 15
multiset::rend() in an inbuilt function in C++ STL which returns a reverse iterator pointing to the theoretical element right before the first element in the multiset container.
Syntax:
reverse_iterator multiset_name.rend()
Parameter: The function does not accepts any parameter.
Return value: The function returns a reverse iterator pointing to the theoretical element right before the first element in the multiset container.
Below program illustrate the multiset::rend() function:
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr[] = { 15, 13, 15, 11, 13, 10 };
multiset< int > s(arr, arr + 6);
multiset< int >::reverse_iterator rit;
for (rit = s.rbegin(); rit != s.rend(); rit++)
cout << *rit << " ";
return 0;
}
|
Output:
15 15 13 13 11 10
Let us see the differences in a tabular form -:
|
multiset rbegin() |
multiset rend() |
1. |
It is used to return a reverse iterator pointing to the last element in the container |
It is used to return a reverse iterator pointing to the theoretical element right before the first element in the multiset container |
2. |
Its syntax is -:
reverse_iterator rbegin();
|
Its syntax is -:
reverse_iterator rend();
|
3. |
It does not take any parameters. |
It does not take any parameters. |
4. |
Its complexity is constant. |
Its complexity does not changes. |
5. |
Its iterator validity does not changes. |
Its iterator validity does not change. |
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...