#include <iostream>
#include <cstdlib>
#include <ctime>
using std::cout;
using std::endl;
inline void swap(int &x, int &y) {
int tmp = x;
x = y;
y = tmp;
}
void selection_sort(int *array, int size) {
int *next, *before, *last = array + size - 1;
for (; array < last; array++)
{
before = array;
for (next = array + 1; next <= last; next++)
if (*before > *next)
before = next;
swap(*array, *before);
}
}
int main()
{
const int size = 20;
int arr[size];
srand((unsigned int)time(NULL));
for (int i = 0; i < size; i++)
arr[i] = (rand() % 1000);
selection_sort(arr, size);
for (int i = 0; i < size; i++)
cout << arr[i] << endl;
return 0;
}
/*
run:
13
26
69
144
191
324
330
344
382
393
600
743
786
835
891
908
950
951
955
998
*/