The Wayback Machine - https://web.archive.org/web/20241006034924/https://www.geeksforgeeks.org/multiset-rbegin-and-rend-function-in-c-stl/
Open In App

multiset rbegin() and rend() function in C++ STL

Last Updated : 12 Jun, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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




// CPP program to demonstrate the
// multiset::rbegin() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
 
    int arr[] = { 15, 12, 15, 11, 10, 10 };
 
    // initializes the set from an array
    multiset<int> s(arr, arr + 6);
 
    multiset<int>::reverse_iterator rit;
 
    // prints all elements in reverse order
    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




// CPP program to demonstrate the
// multiset::rend() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
 
    int arr[] = { 15, 13, 15, 11, 13, 10 };
 
    // initializes the set from an array
    multiset<int> s(arr, arr + 6);
 
    multiset<int>::reverse_iterator rit;
 
    // prints all elements in reverse order
    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.


Previous Article
Next Article

Similar Reads

vector rbegin() and rend() function in C++ STL
vector::rbegin() is a built-in function in C++ STL which returns a reverse iterator pointing to the last element in the container. Syntax: vector_name.rbegin() Parameters: The function does not accept any parameter.Return value: The function returns a reverse iterator pointing to the last element in the container.Program to demonstrate the vector::
2 min read
list rbegin() and rend() function in C++ STL
list::rbegin() is an inbuilt function in C++ STL that returns a reverse iterator which points to the last element of the list. Syntax: list_name.rbegin()Parameter: This function does not accept any parameters. Return value: It returns a reverse iterator which points to the last element of the list. Below program illustrates the above function: C/C+
2 min read
array::rbegin() and array::rend() in C++ STL
array::rbegin() is a built-in function in C++ STL which returns a reverse iterator pointing to the last element in the container. Syntax:array_name.rbegin()Parameters: The function does not accept any parameter. Return value: The function returns a reverse iterator pointing to the last element in the container. Program to demonstrate the array::rbe
2 min read
string::rbegin() and string::rend() in C++
The std::string::rbegin() and std::string::rend() functions in C++ are used to fetch the reverse iterators to the string. They are the member function of std::string and are used when we want to iterate the string in reverse. In this article, we will learn how to use string::rbegin() and string::rend() in C++. string::rbegin()The string::rbegin() f
2 min read
deque rend() function in C++ STL
The deque::rend() is an inbuilt function in C++ STL which returns a reverse iterator which points to the position before the beginning of the deque (which is considered its reverse end). Syntax: deque_name.rend()Parameter: This function does not accept any parameters. Return value: It returns a reverse iterator which points to the position before t
2 min read
map rend() function in C++ STL
The rend() function is an inbuilt function in C++ STL which returns a reverse iterator pointing to the theoretical element right before the first key-value pair in the map(which is considered its reverse end). Syntax: map_name.rend() Parameters:The function does not take any parameter. Return Value: The function returns a reverse iterator pointing
2 min read
deque rbegin() function in C++ STL
The deque::rbegin() is an inbuilt function in C++ STL which returns a reverse iterator which points to the last element of the deque (i.e., its reverse beginning). Syntax: deque_name.rbegin()Parameter: This function does not accept any parameters. Return value: It returns a reverse iterator which points to the last element of the deque. Below progr
2 min read
map rbegin() function in C++ STL
The std::map::rbegin() is a function in C++ STL. It returns a reverse iterator which points to the last element of the map. The reverse iterator iterates in reverse order and incrementing it means moving towards beginning of map. Syntax: r_i rbegin(); const_r_i rbegin() const; Parameters: It does not except any parameters. Returns: It returns a rev
2 min read
multimap rend in C++ STL
multimap::rend() is a built-in function in C++ STL which returns a reverse iterator pointing to the theoretical element preceding to the first element of the multimap container. Syntax multimap_name.rend() Parameters: The function does not take any parameter. Return ValueThe function returns a reverse iterator pointing to the reverse end of the mul
2 min read
multimap rbegin in C++ STL
multimap::rbegin() is a built-in-function in C++ STL which returns an iterator pointing to the last element of the container. Syntax: multimap_name.rbegiin() Parameters: The function does not take any parameter. Return Value: The function returns a reverse iterator pointing to the last element of the container. (Note: Reverse iterators iterate back
2 min read
multiset crbegin() and crend() function in C++ STL
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.
2 min read
multiset cbegin() and cend() function in C++ STL
The multiset::cbegin() is a built-in function in C++ STL which returns a constant iterator pointing to the first element in the container. The iterator cannot be used to modify the elements in the set container. The iterators can be increased or decreased to traverse the set accordingly. Syntax: constant_iterator multiset_name.cbegin() Parameters:
3 min read
multiset begin() and end() function in C++ STL
The multiset::begin() is a built-in function in C++ STL that returns an iterator pointing to the first element in the multiset container. Since multiset always contains elements in an ordered way, begin() always points to the first element according to the sorting criterion. Syntax: iterator multiset_name.begin() Parameters: The function does not a
2 min read
multiset insert() function in C++ STL
The multiset::insert() is a built-in function in C++ STL which insert elements in the multiset container or inserts the elements from a position to another position from one multiset to a different multiset. Syntax: iterator multiset_name.insert(element)Time Complexity: O(log n) Since the elements are always in sorted order, the newly inserted elem
4 min read
multiset find() function in C++ STL
The multiset::find() is a built-in function in C++ STL which returns an iterator pointing to the lower_bound of the element which is searched in the multiset container. If the element is not found, then the iterator points to the position past the last element in the set. Syntax: multiset_name.find(element) Parameters: The function accepts one mand
2 min read
multiset equal_range() function in C++ STL
The multiset::equal_range() is a built-in function in C++ STL which returns an iterator of pairs. The pair refers to the range that includes all the elements in the container which have a key equivalent to k. The lower bound will be the element itself and the upper bound will point to the next element after key k. If there are no elements matching
3 min read
multiset clear() function in C++ STL
The multiset::clear() function is a built-in function in C++ STL which removes all elements from the multiset container. The final size of multiset container after removal is 0. Syntax: multiset_name.clear() Parameters: The function does not accept any parameter. Return Value: The function does not returns anything. Below programs illustrates the m
2 min read
multiset empty() function in C++ STL
The multiset::empty() function is a built-in function in C++ STL which checks if the multiset is empty or not. It returns true if the multiset is empty, else it returns false. Syntax: multiset_name.empty() Parameters: The function does not accept any parameter. Return Value: The function returns true if the multiset is empty, else it returns false.
1 min read
multiset count() function in C++ STL
The multiset::count() function is a built-in function in C++ STL that searches for a specific element in the multiset container and returns the number of occurrences of that element. Syntax: multiset_name.count(val) Parameters: The function accepts a single parameter val which specifies the element to be searched in the multiset container. Return V
2 min read
multiset emplace_hint() function in C++ STL
The multiset::emplace_hint() is a built-in function in C++ STL which inserts a new element in the multiset. A position is passed in the parameter of the function which acts as a hint from where the searching operation starts before inserting the element at its current position. The position only helps the process to get faster, it does not decide w
3 min read
multiset get_allocator() function in C++ STL
The multiset::get_allocator() method in C++ STL is a built-in function in C++ STL which returns a copy of the allocator object associated with the multiset. Syntax: multiset_name.get_allocator() where allocator_type is the type of the allocator used by the container. Parameters: The function does not take any parameter. Return Value: This method re
1 min read
multiset::operator= in C++ STL
Multisets are a type of associative containers similar to set, with an exception that multiple elements can have same values. multiset::operator= This operator is used to assign new contents to the container by replacing the existing contents. It also modifies the size according to the new contents.Syntax : multisetname1 = (multisetname2) Parameter
3 min read
multiset::swap() in C++ STL
Multisets are a type of associative containers similar to set, with an exception that multiple elements can have same values. multiset::swap() This function is used to exchange the contents of two multisets but the sets must be of same type, although sizes may differ. Syntax : multisetname1.swap(multisetname2) Parameters : The name of the multiset
3 min read
multiset::emplace() in C++ STL
Multisets are a type of associative containers similar to set, with an exception that multiple elements can have same values. multiset::emplace() This function is used to insert a new element into the multiset container. Syntax : multisetname.emplace(value) Parameters : The element to be inserted into the multiset is passed as the parameter. Result
3 min read
multiset lower_bound() in C++ STL with Examples
The multiset::lower_bound() is a built-in function in C++ STL which returns an iterator pointing to the first element in the container which is equivalent to k passed in the parameter. In case k is not present in the set container, the function returns an iterator pointing to the immediate next element which is just greater than k. If the key passe
3 min read
multiset upper_bound() in C++ STL with Examples
The multiset::upper_bound() is a built-in function in C++ STL that returns an iterator pointing to the immediate next element which is just greater than k. If the key passed in the parameter exceeds the maximum key in the container, then the iterator returned points an element which points to the position after the last element in the container. Sy
3 min read
multiset max_size() in C++ STL with Examples
The multiset::max_size() is a built-in function in C++ STL which returns the maximum number of elements a multiset container can hold. Syntax: multiset_name.max_size() Parameters: The function does not accept any parameters. Return Value: The function returns the maximum number of elements a multiset container can hold. Below programs illustrate th
1 min read
multiset size() in C++ STL with Examples
The multiset::size() is a built-in function in C++ STL which returns the number of elements in the multiset container. Syntax: multiset_name.size() Parameters: The function does not accept any parameters. Return Value: The function returns the number of elements in the multiset container. Below programs illustrate the above function: Program 1: //
2 min read
multiset max_size() in C++ STL
The multiset::max_size() is an observer function in C++ STL which returns the maximum number of elements a container can hold. This limit might be due to system or library implementations. Being an observer function it does not modify the multiset in any way. Syntax: multiset_name.max_size() Parameters: This function does not accept any parameters.
1 min read
Multiset in C++ Standard Template Library (STL)
Multisets are a type of associative containers similar to the set, with the exception that multiple elements can have the same values. Some Basic Functions associated with multiset: begin() - Returns an iterator to the first element in the multiset --> O(1)end() - Returns an iterator to the theoretical element that follows the last element in th
6 min read
Practice Tags :