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