Anonymous user
Sorting algorithms/Insertion sort: Difference between revisions
m
size_t & comment
m (some comments) |
m (size_t & comment) |
||
Line 1,074:
<lang c>#include <stdio.h>
void insertion_sort(int
void insertion_sort(int *a, size_t n) {
for(size_t i = 1; i < n; ++i) {
int
size_t j = i;
while( (j > 0) &&
a[j] = a[j - 1];
--j;
}
a[j] =
}
}
int main (int argc, char** argv) {
int a[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1};
for
printf("%d%s", a[i], (i == (n - 1))? "\n" : " ");
insertion_sort(a, n);
for
printf("%d%s", a[i], (i == (n - 1))? "\n" : " ");
return 0;
}
|