Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
rotate.cpp
Go to the documentation of this file.
1
29#include <algorithm> // for rotate
30#include <iostream> // for cout, endl
31#include <iterator> // for ostream_iterator
32#include <vector> // for vector
33
34#include <examples.h>
35
36
37int main ()
38{
39 typedef std::vector<int, std::allocator<int> > Vector;
40
41 // Initialize a vector with an array of integers.
42 const Vector::value_type arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
43 Vector v (arr + 0, arr + sizeof arr / sizeof *arr);
44
45 typedef std::ostream_iterator<int, char, std::char_traits<char> > Iter;
46
47 // Print out elements in original (sorted) order.
48 std::cout << "Elements before rotate: \n ";
49 std::copy (v.begin (), v.end (), Iter (std::cout, " "));
50
51 // Rotate the elements.
52 std::rotate (v.begin (), v.begin () + 4, v.end ());
53
54 // Print out the rotated elements.
55 std::cout << "\n\nElements after rotate: \n ";
56 std::copy (v.begin (), v.end (), Iter (std::cout, " "));
57 std::cout << std::endl;
58
59 return 0;
60}
#define v
Definition 17.names.cpp:138
std::vector< UserClass, std::allocator< UserClass > > Vector
std::ostream_iterator< int, char, std::char_traits< char > > Iter
Definition alg7.cpp:64
int main()
Definition rotate.cpp:37