
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
multimap::rbegin() in C++ STL
In this article we will be discussing the working, syntax, and examples of multimap::rbegin() function in C++ STL.
What is Multimap in C++ STL?
Multimaps are the associative containers, which are similar to map containers. It also facilitates to store the elements formed by a combination of key-value and mapped value in a specific order. In a multimap container, there can be multiple elements associated with the same key. The data is internally always sorted with the help of its associated keys.
What is multimap::rbegin()?
multimap::rbegin() function is an inbuilt function in C++ STL, which is defined in <map> header file. rbegin() implies reverse begin to function, this function is the reverse of the begin(). This function returns an iterator which is pointing to the last element of the multimap container.
Syntax
multiMap_name.rbegin();
Parameter
This function accepts no parameter.
Return value
This function returns the iterator which is pointing to the last element of the multimap container.
Input
multimap<char, int> newmap; newmap[‘a’] = 1; newmap[‘b’] = 2; newmap[‘c’] = 3; newmap.rbegin();
Output
c:3
Example
#include <bits/stdc++.h> using namespace std; int main(){ multimap<int, int>mul; //inserting elements in multimap mul.insert({ 1, 10 }); mul.insert({ 2, 20 }); mul.insert({ 3, 30 }); mul.insert({ 4, 40 }); mul.insert({ 5, 50 }); //fetching first element using rbegin() cout<<"First element is: "<<mul.rbegin()->first<<","<<mul.rbegin()->second; //displaying multimap elements cout << "\nElements in multimap is : \n"; cout << "KEY\tELEMENT\n"; for (auto it = mul.rbegin(); it!= mul.rend(); ++it){ cout << it->first << '\t' << it->second << '\n'; } return 0; }
Output
If we run the above code it will generate the following output −
First element is: 5,50 Elements in multimap is : KEY ELEMENT 5 50 4 40 3 30 2 20 1 10