Uses of Reverse Iterators

Reverse iterators are ordinary iterators except that they invert the semantic of the overloaded ++ and — operators. They are useful when the elements of a container are accessed in reverse order. For example:

 #include #include #include using namespace std;void ascending_order(vector  &v) {      //display elements of v in ascending order  for (vector::reverse_iterator rp = v.rbegin(); rp < v.rend(); rp++)  {    cout<< *rp<

The member functions rbegin() and rend() (reverse begin() and reverse end()) are similar to begin() and end() except that they return reverse iterators, which apply to reverse sequences.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: