English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ Deque rend() Usage and Example

C++ Deque (Double-Ended Queue)

C ++ The Deque rend() function returns a reverse iterator that refers to the element before the first element in the deque container. Like the end() function, the iterator can be incremented or decremented.

Wherein, rend() represents the reverse end.

Syntax

reverse_iterator rend();

Parameters

It does not contain any parameters.

Return value

It returns a reverse iterator that points to the reverse end of the deque container.

Instance1

Let's look at a simple example

#include #include using namespace std;
int main()
{
   dequec={'T','u','t','o','r','i','a','l'};
   deque::reverse_iterator ritr;
   for(ritr=c.rbegin();ritr!=c.rend();++ritr)
   {
          cout<<*ritr;
   }
   return 0;
}

Output:

lairotuT

In this example, a reverse iterator is used to iterate backward and continue until and unless it equals c.rend(). It prints the reverse content of the deque c, that is, lairotuT

Instance2

Let's see a simple example where the reverse iterator is decremented2.

#include #include using namespace std;
int main()
{
   deque i={1,2,3,4,5};
   deque::reverse_iterator ritr = i.rend()-2;
   cout<<*ritr;
   return 0;
}

Output:

2

In this example, the reverse iterator is decremented2Therefore, it accesses the second element of the deque.

C++ Deque (Double-Ended Queue)