Sorting algorithms/Insertion sort: Difference between revisions

Content added Content deleted
(→‎{{header|Perl}}: Rather not use a statement label if I can help it)
(→‎{{header|C}}: Keep indexing the same as the shell sort)
Line 195: Line 195:
for (i = 1; i < n; i++) {
for (i = 1; i < n; i++) {
k = a[i];
k = a[i];
for (j = i - 1; j >= 0 && k < a[j]; j--) {
for (j = i; j > 0 && k < a[j - 1]; j--) {
a[j + 1] = a[j];
a[j] = a[j - 1];
}
}
a[j + 1] = k;
a[j] = k;
}
}
}
}