Reverse a stack of integers : reverse « STL Algorithms Modifying sequence operations « C++ Tutorial






#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
   
int main()
{
  vector<int> v;
  unsigned int i;
   
  for(i=0; i<10; i++) v.push_back(i);
   
  cout << "Initial: ";
  for(i=0; i<v.size(); i++) 
     cout << v[i] << endl;
   
  reverse(v.begin(), v.end());
   
  for(i=0; i<v.size(); i++) 
    cout << v[i] << endl;
   
  return 0;
}








24.16.reverse
24.16.1.Use reverse to reverse the order of elements
24.16.2.Use reverse to reverse order from second to last element but one
24.16.3.Using the STL generic reverse algorithm with a vector
24.16.4.Reverse the order of the found element with value 3 and all following elements
24.16.5.Reverse a stack of integers