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 28 29 30 31 32 33 34 35
| #ifndef ALGORITHM_INSERTION_SORT_H #define ALGORITHM_INSERTION_SORT_H
void insertion_sort (int array[], int array_size) { int i, j;
for (i = 1; i < array_size; i++) { j = i; while ((j > 0) && (array[j-1] > array[j])) { swap(&array[j-1], &array[j]); j--; } printf("step %2d: ",i); print_array(array,array_size); }
}
#endif
|