Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
random_shuffle.cpp
Go to the documentation of this file.
1
29#include <algorithm> // for random_shuffle
30#include <iostream> // for cout
31#include <iterator> // for ostream_iterator
32#include <string> // for string
33
34// #include <examples.h>
35
36
37int main ()
38{
39 // Create a string of doubles (unusual? maybe, but why not...)
40 typedef std::char_traits<double> Traits;
41 typedef std::allocator<double> Allocator;
42 typedef std::basic_string<double, Traits, Allocator> Bizarre;
43
44 // Initialize a Bizarre with an array of values.
45 const Bizarre::value_type a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
46
47 Bizarre b (a + 0, a + sizeof a / sizeof *a);
48
49 typedef std::ostream_iterator<double, char, std::char_traits<char> >
50 Iter;
51
52 // Suppress decimal point in output.
53 std::cout.precision (0);
54 std::cout.setf (std::cout.fixed, std::cout.floatfield);
55
56 // Print out elements in original (sorted) order.
57 std::cout << "Elements before random_shuffle: \n ";
58 std::copy (b.begin (), b.end (), Iter (std::cout," "));
59
60 // Mix them up with random_shuffle.
61 std::random_shuffle (b.begin (), b.end ());
62
63 // Print out the mixed up elements.
64 std::cout << "\n\nElements after random_shuffle: \n ";
65 std::copy (b.begin (), b.end (), Iter (std::cout, " "));
66 std::cout << '\n';
67
68 return 0;
69}
#define Allocator
Definition 17.names.cpp:440
#define Traits
Definition 17.names.cpp:556
#define a
Definition 17.names.cpp:109
#define b
Definition 17.names.cpp:110
#define floatfield
#define fixed
std::ostream_iterator< int, char, std::char_traits< char > > Iter
Definition alg7.cpp:64
int main()