#include <stdio.h>
#include <time.h>
#include <stdlib.h>
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(void)
{
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++)
printf("%d\n", arr[i]);
return 0;
}
/*
run:
32
143
186
225
241
400
426
441
610
653
670
752
769
770
800
812
825
867
913
998
*/