Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
partial_sort.cpp
Go to the documentation of this file.
1
29#include <algorithm> // for partial_sort
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 typedef std::ostream_iterator<int, char, std::char_traits<char> > Iter;
41
42 const Vector::value_type a[] = {
43 17, 3, 5, -4, 1, 12, -10, -1, 14, 7,
44 -6, 8, 15, -11, 2, -2, 18, 4, -3, 0
45 };
46
47 Vector v1 (a + 0, a + sizeof a / sizeof *a);
48
49 // Output original vector.
50 std::cout << "For the vector: ";
51 std::copy (v1.begin (), v1.end (), Iter (std::cout, " "));
52
53 // Partial sort the first seven elements.
54 std::partial_sort (v1.begin (), v1.begin () + 7, v1.end ());
55
56 // Output result.
57 std::cout << "\n\nA partial_sort of seven elements gives: \n ";
58 std::copy (v1.begin (), v1.end (), Iter (std::cout, " "));
59 std::cout << std::endl;
60
61 // A vector of ten elements.
62 Vector v2 (Vector::size_type (10), 0);
63
64 // Sort the last ten elements in v1 into v2.
65 std::partial_sort_copy (v1.begin () + 10, v1.end (),
66 v2.begin (), v2.end ());
67
68 // Output result.
69 std::cout
70 << "\nA partial_sort_copy of the last ten elements gives: \n ";
71 std::copy (v2.begin (), v2.end (), Iter (std::cout, " "));
72
73 std::cout << std::endl;
74
75 return 0;
76}
#define v2
Definition 17.names.cpp:271
#define a
Definition 17.names.cpp:109
#define v1
Definition 17.names.cpp:245
std::vector< UserClass, std::allocator< UserClass > > Vector
std::ostream_iterator< int, char, std::char_traits< char > > Iter
Definition alg7.cpp:64
int main()