Use a reverse_iterator to go from the end to the beginning : reverse_iterator « STL Algorithms Iterator « C++ Tutorial






#include <iostream>
#include <list>
#include <algorithm>
#include <string>

using namespace std;

static const int ARRAY_SIZE = 5;

int main( ) {
   list<string> lstStr;

   lstStr.push_back("A");
   lstStr.push_back("B");
   lstStr.push_back("C");
   lstStr.push_back("D");

   for (list<string>::iterator p = lstStr.begin( );
        p != lstStr.end( ); ++p) {
      cout << *p << endl;
   }

   for (list<string>::reverse_iterator p = lstStr.rbegin( );
        p != lstStr.rend( ); ++p) {
      cout << *p << endl;
   }
}
A
B
C
D
D
C
B
A








30.6.reverse_iterator
30.6.1.reverse iterator and find
30.6.2.Use a reverse_iterator to go from the end to the beginning