Below is an Insertion Sort implemented in C:
void insert (int *array, int num, int x) {
int i;
for (i = n-1; i >= 0; i--) {
if (x < array[i]) array[i+1] = a[i] else break;
}
array[i+1] = x;
}
void insertion_sort (int *array, int n) {
int i;
for (i = 0; i < n; i++) {
insert(array, i, array[i]);
}
}
|