selection_sort() ascending

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
selection_sort ascending
n - size of array, sort_array[] - integer's array
// name: Isakov Nikita
MISIS, 2013
*/
for (int i = 0; i < n; ++i)
{
int imin = i;
for (int j = i + 1; j < n; ++j)
if ( sort_array[j] < sort_array[imin] )
{
imin = j;
}
swap(sort_array[i], sort_array[imin]);
}