edited by
224 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
edited by

1 Answer

1 votes
1 votes

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

Related questions

0 votes
0 votes
2 answers
1
gatecse asked Mar 2, 2018
737 views
Bluetooth uses ____ method in physical layer to avoid interference from other devices or other networksFHSSFDSSTDSNone of the above
0 votes
0 votes
1 answer
2
gatecse asked Mar 2, 2018
362 views
In which of the following search agent operates by interleaving computation and action?Offline searchOnline searchBreadth first searchDepth first search
0 votes
0 votes
1 answer
3
gatecse asked Mar 2, 2018
360 views
Which of the following deals with the precise model where accurate solutions are achieved quickly?Soft computingMobile computingHard computingNone of the above
0 votes
0 votes
1 answer
4
gatecse asked Mar 2, 2018
481 views
Supervised learning and unsupervised learning are two board category ofData warehouseDBMSNeural NetworkNone of the above