Skip to content
Related Articles

Related Articles

deque rbegin() function in C++ STL
  • Difficulty Level : Basic
  • Last Updated : 30 Aug, 2018
GeeksforGeeks - Summer Carnival Banner

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:






// 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;
}
Output:
The deque in reverse order: 50 40 30 20 10

Program 2:




// 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;
}
Output:
The deque in reverse order: e d c b a
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up
Recommended Articles
Page :