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
| #ifndef ALGORITHM_SELECTION_SORT_H #define ALGORITHM_SELECTION_SORT_H
void selection_sort (int array[], int array_size) { int i, j, min_index;
for (i = 0; i < array_size-1; i++) { min_index = i; for (j = i + 1; j < array_size; j++) { if (array[j] < array[min_index]) { min_index = j; } } swap(&array[min_index], &array[i]); printf("step %2d: ",i+1); print_array(array,array_size); } }
#endif
|