Sorting algorithms/Insertion sort: Difference between revisions

Fixed a few naming and operator issues. "Isort" to "insertion_sort". "i <= n - 1" to "i < n". "j -= 1" to "j--". That sort of thing.
(→‎{{header|Groovy}}: swap dots added)
(Fixed a few naming and operator issues. "Isort" to "insertion_sort". "i <= n - 1" to "i < n". "j -= 1" to "j--". That sort of thing.)
Line 190:
 
=={{header|C}}==
<lang c>#include <stdio.h>
void insertion_sort (int *a, int n) {
void Isort( int a[]i, intj, size)k;
for (i =0 1; i <= n-1; i++) {
{
int i, j, temp k = a[i];
for (j = i - 1; j >= 0 && k < a[j]; j--) {
a[j + 1] = a[j];
for(i=1; i<=size-1; i++)
{ }
temp = a[ij + 1] = k;
j = i-1;
while(j>=0 && a[j] > temp)
{
a[j+1] = a[j];
j -= 1;
}
a[j+1] = temp;
}
}
 
int main (int) argc, char *argv[]){
int a[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1};
{
int intArray[]n = {4,sizeof 65,a 2,/ -31,sizeof a[0, 99, 2, 83, 782, 1}];
int i insertion_sort(a, n);
return 0;
}
n = sizeof(intArray)/sizeof(intArray[0]);
}</lang>
Isort(intArray, n);
for(i=0; i<=n-1; i++)
printf("%d ", intArray[i]);
}</lang>
 
=={{header|C++}}==
Anonymous user