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

C++ Deque rbegin() Usage and Example

C++ Deque (Double-ended Queue)

C ++ The rbegin() function of Deque returns the first data of the reverse queue. The iterator can be incremented or decremented, but cannot modify the content of the deque.

Where, rbegin() indicates the reverse start.

Syntax

reverse_iterator rbegin();

Parameters

It does not contain any parameters.

Return value

It returns a reverse iterator to the last element of the deque.

Instance1

Let's look at a simple example

#include#include using namespace std;
int main()
{
 dequedeq = {1,2,3,4,5};
 deque::reverse_iterator ritr = deq.rbegin();
 for(ritr = deq.rbegin(); ritr != deq.rend();++ritr)
 {
  cout<<*ritr;
  cout << " \t ";
  } 
   return 0;
}

Output:

5 4 3 2 1

In this example, the rbegin() function reverses the content of the deque by iterating from the end and moving towards the beginning of the container.

Instance2

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

#include#include using namespace std;
int main()
{
   dequed={"java",".net","C","C++"};
   deque::reverse_iterator ritr = d.rbegin()+1;
   cout<<*ritr;
   return 0;}

Output:

C

In this example, the reverse iterator is incremented1Therefore, the rbegin() function accesses the second element from the back.

C++ Deque (Double-ended Queue)