C++ list loop reverse
#include <iostream> #include <list> using namespace std; int main()/*from w w w. j a v a 2s . c om*/ { 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; }