Sorting algorithms/Insertion sort: Difference between revisions
Content added Content deleted
(→{{header|C}}: use t for temporary variable to fit in with the other C examples) |
(→{{header|C}}: Remove print_array function) |
||
Line 237: | Line 237: | ||
a[j] = t; |
a[j] = t; |
||
} |
} |
||
⚫ | |||
void print_array (int *a, int n) { |
|||
int i; |
|||
⚫ | |||
⚫ | |||
} |
|||
printf("\n"); |
|||
} |
} |
||
Line 250: | Line 242: | ||
int a[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1}; |
int a[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1}; |
||
int n = sizeof a / sizeof a[0]; |
int n = sizeof a / sizeof a[0]; |
||
int i; |
|||
⚫ | |||
⚫ | |||
insertion_sort(a, n); |
insertion_sort(a, n); |
||
for (i = 0; i < n; i++) |
|||
printf("%d%s", a[i], i == n - 1 ? "\n" : " "); |
|||
return 0; |
return 0; |
||
⚫ | |||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
4 65 2 -31 0 99 2 83 782 1 |
|||
-31 0 1 2 2 4 65 83 99 782 |
|||
</pre> |
</pre> |
||