Using the STL generic reverse algorithm with a vector : reverse « STL Algorithms Modifying sequence operations « C++ Tutorial






#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm> // For reverse
using namespace std;
template <typename Container>

Container make(const char s[])
{
  return Container(&s[0], &s[strlen(s)]);
}

int main()
{
  vector<char> vector1 = make< vector<char> >("abc");
  reverse(vector1.begin(), vector1.end());
  assert (vector1 == make< vector<char> >("cba"));
  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