Demonstrate reverse iterator - C++ STL

C++ examples for STL:reverse_iterator

Description

Demonstrate reverse iterator

Demo Code

#include <iostream>
#include <list>
using namespace std;
int main()//from   w  w  w . j  a  v a 2 s.  c  o m
{
   int arr[] = { 2, 4, 6, 8, 10 };       // array of ints
   list<int> theList;
   for(int j=0; j<5; j++)                // transfer array
      theList.push_back( arr[j] );       // to list
   list<int>::reverse_iterator revit;    // reverse iterator
   revit = theList.rbegin();             // iterate backwards
   while( revit != theList.rend() )      // through list,
      cout << *revit++ << ' ';           // displaying output
   cout << endl;
   return 0;
}

Result


Related Tutorials