/* * selection_sort.c * * Sort an array, by gradually building up the sorted array. * At each iteration: * - The beginning part of the array contains the lowest elements, * in sorted order. * - Find the minimum element in the unsorted part of the array. * - Add it to the end of the sorted part. */ #include void print_array(int n, int a[]) { int i; for (i=0; i a[j]) { tmp = a[i]; a[i] = a[j]; a[j] = tmp; } } } } int main() { int a[100] = {56, 6, 58, 20, 8, 45, 56, 12, 60}; print_array(9, a); selection_sort(9, a); print_array(9, a); return 0; }