- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 rend in C++ STL
In this article we will be discussing the working, syntax, and examples of multimap::rend() 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::rend()?
multimap::rend() function is an inbuilt function in C++ STL, which is defined in
Syntax
multiMap_name.rend();
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.rend();
Output
error
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 }); //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 −
Elements in multimap is : KEY ELEMENT 5 50 4 40 3 30 2 20 1 10