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 programs illustrates the above function:
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// deque::rbegin() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    deque<int> dq = { 10, 20, 30, 40, 50 };
  
    cout << "The deque in reverse order: ";
  
    // prints the elements in reverse order
    for (auto it = dq.rbegin(); it != dq.rend(); ++it)
        cout << *it << " ";
  
    return 0;
}

chevron_right


Output:

The deque in reverse order: 50 40 30 20 10

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// deque::rbegin() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    deque<char> dq = { 'a', 'b', 'c', 'd', 'e' };
  
    cout << "The deque in reverse order: ";
  
    // prints the elements in reverse order
    for (auto it = dq.rbegin(); it != dq.rend(); ++it)
        cout << *it << " ";
  
    return 0;
}

chevron_right


Output:

The deque in reverse order: e d c b a

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.


Article Tags :
Practice Tags :


2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.