devxlogo

Uses of Reverse Iterators

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.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist