Reverse a sequence : reverse « STL Algorithms Modifying sequence operations « C++






Reverse a sequence

  
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void show(const char *msg, vector<int> vect);

int main()
{
  vector<int> v;

  for(int i=0; i<10; i++) v.push_back(i);

  show("Original order: ", v);

  reverse(v.begin(), v.end());
  show("After reversal: ", v);

  return 0;
}

void show(const char *msg, vector<int> vect) {
  cout << msg << endl;
  for(unsigned i=0; i < vect.size(); ++i)
    cout << vect[i] << endl;
}
  
    
  








Related examples in the same category

1.Use reverse to reverse the order of elements
2.Use reverse to reverse order from second to last element but one
3.Using the STL generic reverse algorithm with a vector
4.Reverse the order of the found element with value 3 and all following elements
5.Sort and reverse an int array