Skip to content
Related Articles

Related Articles

deque rend() function in C++ STL

View Discussion
Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 16 Jun, 2022

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 the beginning of the deque. Below program illustrates the above function: Program 1: 

CPP




// C++ program to illustrate the
// deque::rend() 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

Time complexity: O(1)

Auxiliary Space: O(1)

Program 2: 

CPP




// C++ program to illustrate the
// deque::rend() 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

Time complexity: O(1)

Auxiliary Space: O(1)


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!