blob: ff5a7b6cf50e7aff558375e2e320ccf50e4b9bf2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#include <iostream>
#include <vector>
#include <ostream>
template<class T> void
straight_selection(std::vector<T> &array)
{
for (int i = 0; i < array.size(); ++i)
{
int k = i;
int x = array[i];
for (int j = i; j < array.size(); ++j)
{
if (array[j] < x)
{
k = j;
x = array[j];
}
}
array[k] = array[i];
array[i] = x;
}
}
template<class T> std::ostream &
operator<<(std::ostream &stream, std::vector<T> &v)
{
if (v.size() == 0) stream << "{ }";
stream << "array = { ";
for (int i = 0; i < int(v.size()) - 1; ++i)
stream << v[i] << ", ";
stream << v.back() << " }";
return stream;
}
int
main()
{
std::vector<int> array = { 2, 7, 12, 30, 11, 4, 12, 5, 20 };
std::cout << array << std::endl;
straight_selection(array);
std::cout << array << std::endl;
return 0;
}
|