You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
537 B

#include <stdio.h>
void insertion_sort(int * a, int len_a);
int
main(int argc, char ** argv)
{
int i;
int l[] = {1, 4, 8, 9, 2, 3};
insertion_sort(l, 6);
for (i = 0; i < 6; i++) {
printf("%d\n", l[i]);
}
}
void
insertion_sort(int * a, int len_a)
{
int i, j, key;
for (j = 1; j < len_a; j++) {
key = a[j];
i = j - 1;
while ((i >= 0) && (a[i] > key)) {
a[i + 1] = a[i];
i = i - 1;
}
a[i + 1] = key;
}
}
/* vim:filetype=c
*/