in Unknown Category edited by
240 views
0 votes
0 votes

To use a reverse-iterator, you should

  1. begin by initializing it to end ( )
  2. begin by initializing it to rend ( )
  3. increment it to move backward through the container
  4. decrement it to move backward through the container
in Unknown Category edited by
by
240 views

1 comment

Kindly answer this
0
0

1 Answer

1 vote
1 vote

Answer: Option C) increment it to move backward through the container

A reverse iterator is used to iterate backwards. 

To iterate backwards use rbegin() and rend() as the iterators for the end of the collection, and the start of the collection respectively. 

Incrementing a reverse_interator moves it backward. We need to initialize it to rbegin()

Eg:-

for (vector<my_class>::reverse_iterator i = my_vector.rbegin(); 
        i != my_vector.rend(); ++i ) {}

 

Iterating C++ vector from the end to the beginning - Stack Overflow