English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C++ Deque (Double-ended Queue)
C ++The crbegin() function of deque returns a constant reverse iterator that refers to the last element of the deque. The iterator can be incremented or decremented, but cannot modify the content of the deque.
Where, crbegin() indicates a constant reverse start.
const_reverse_iterator crbegin();
It does not contain any parameters.
It returns a constant reverse iterator that points to the last element in the deque container.
Let's look at a simple example
#include#includeusing namespace std; int main() { deque i={10,20,30,40,50}; deque::const_reverse_iterator citr; for(citr=i.crbegin();citr!=i.crend();++citr) { cout<<*citr; cout << " "; } return 0;
Output:
50 40 30 20 10
In this example, the crbegin() function is used to return an iterator to the last element of the deque, and the for loop is iterated until it reaches the first element of the deque.
Let's look at a simple example when the iterator is incremented.
#include#includeusing namespace std; int main() { deque fruit = {"electronics", "computer science", "mechanical", "electrical"}; deque::const_reverse_iterator citr = fruit.crbegin()+1; cout<<*citr; return 0; }
Output:
mechanical
In this example, the constant reverse iterator is incremented1Therefore, it accesses the second element from the back.