procedure insertion sort(a[1], a[2], a[3]... a[n] : real numbers with n>= 2) for j := 2 to n begin i := 1 while a[j] >a[i] i := i + 1 m := a[j] for k := 0 to j - i - 1 a[j-k] := a[j-k-1] a[i] := m endNOTE: I added square brackets into the notation in place of a subscript.
So far I have this working draft in C:
void insertion_sort() {
int i,j,k,m;
int n = ELEMENTS-1;
for (j=1; j<n; j++) {
i=0;
while (arr[j] > arr[i])
++i;
m = arr[j];
for(k=0; k>j-i-1; k--)
arr[j-k] = arr[j-k-1];
arr[i] = m;
}
}


Sign In
Create Account


Back to top









