multimap::crbegin() and multimap::crend() in C++ STL
- multimap::crbegin() is a built-in function in C++ STL which returns a constant reverse iterator referring to the last element in the multimap container. Since multimap container contains the element in an ordered way, crbegin() will point to that element that will come last according to the container’s sorting criterion.
Syntax:
multimap_name.crbegin()
Parameters: The function does not accept any parameter.
Return Value: The function returns a constant reverse iterator referring to the last element in the multimap container.
// C++ program to illustrate// multiset::crbegin() function#include <bits/stdc++.h>usingnamespacestd;intmain(){// initialize containermultimap<int,int> mp;// insert elements in random ordermp.insert({ 2, 30 });mp.insert({ 1, 40 });mp.insert({ 3, 60 });mp.insert({ 4, 20 });mp.insert({ 5, 50 });autoite = mp.crbegin();cout <<"The last element is {"<< ite->first<<", "<< ite->second <<"}\n";// prints the elementscout <<"\nThe multimap in reverse order is: \n";cout <<"KEY\tELEMENT\n";for(autoitr = mp.crbegin(); itr != mp.crend(); ++itr) {cout << itr->first<<'\t'<< itr->second <<'\n';}return0;}chevron_rightfilter_noneOutput:The last element is {5, 50} The multimap in reverse order is: KEY ELEMENT 5 50 4 20 3 60 2 30 1 40 - multimap::crend() is a built-in function in C++ STL which returns a constant reverse iterator pointing to the theoretical element before the first element in the multimap. Since multimap container contains the element in an ordered way, crend() will point to the element theoretically before the first element according to the container’s sorting criterion.
Syntax:
multimap_name.crend()
Parameters: The function does not accept any parameter.
Return Value: The function returns a constant reverse iterator pointing to the theoretical element before the first element in the multimap.
// C++ program to illustrate// multiset::crend() function#include <bits/stdc++.h>usingnamespacestd;intmain(){// initialize containermultimap<int,int> mp;// insert elements in random ordermp.insert({ 2, 30 });mp.insert({ 1, 40 });mp.insert({ 3, 60 });mp.insert({ 4, 20 });mp.insert({ 5, 50 });// prints the elementscout <<"\nThe multimap in reverse order is : \n";cout <<"KEY\tELEMENT\n";for(autoitr = mp.crbegin(); itr != mp.crend(); ++itr) {cout << itr->first<<'\t'<< itr->second <<'\n';}return0;}chevron_rightfilter_noneOutput:The multimap in reverse order is : KEY ELEMENT 5 50 4 20 3 60 2 30 1 40
Recommended Posts:
- Different ways to use Const with Reference to a Pointer in C++
- std::to_address in C++ with Examples
- Program to create Custom Vector Class in C++
- std::is_trivially_copy_constructible in C/C++
- Difference between Python and C++
- tgamma() method in C/C++ with Examples
- boost::type_traits::is_array Template in C++
- boost is_pointer template in C++
- Stack of Pair in C++ STL with Examples
- Modulo Operator (%) in C/C++ with Examples
- fpclassify() method in C/C++ with Examples
- Operator Overloading '<<' and '>>' operator in a linked list class
- How to find the Entry with largest Value in a C++ Map
- Visibility Modes in C++ with Examples
- Program to implement Separate Chaining in C++ STL without the use of pointers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

