Related Articles

Related Articles

multiset crbegin() and crend() function in C++ STL
  • Last Updated : 17 Nov, 2020

The multiset::crbegin() is a built-in function in C++ STL which returns a constant reverse iterator pointing to the last element in the container. The iterator cannot be used to modify the elements in the multiset container. The iterators can be increased or decreased to traverse the set accordingly. 

Syntax: 

constant_reverse_iterator multiset_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. 

Below programs illustrate the multiset::crbegin() method.



C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to demonstrate the
// multiset::crbegin() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
 
    int arr[] = { 14, 10, 15, 11, 10 };
 
    // initializes the set from an array
    multiset<int> s(arr, arr + 5);
 
    cout << "The last element: " << *(s.crbegin()) << endl;
    // prints all elements in set
    for (auto it = s.crbegin(); it != s.crend(); it++)
        cout << *it << " ";
 
    return 0;
}

chevron_right


Output: 

The last element: 15
15 14 11 10 10






 

The multiset::crend() is a built-in function in C++ STL which returns a constant reverse iterator pointing to the position just before the first element in the container. The iterator cannot be used to modify the elements in the multiset container. The iterators can be increased or decreased to traverse the set accordingly. 

Syntax: 

constant_reverse_iterator multiset_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 multiset container. 

Below programs illustrate the multiset::crend() method. 

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to demonstrate the
// multiset::crend() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
 
    int arr[] = { 14, 12, 15, 11, 10, 10, 16, 16 };
 
    // initializes the set from an array
    multiset<int> s(arr, arr + 8);
 
    // prints all elements in set
    for (auto it = s.crbegin(); it != s.crend(); it++)
        cout << *it << " ";
 
    return 0;
}

chevron_right


Output: 

16 16 15 14 12 11 10 10






 

 

Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.




My Personal Notes arrow_drop_up
Recommended Articles
Page :