Example code in C:
/* Insertion sort for integers */
void insertion( int a[], int n ) {
int i, j, v;
for(i=1;i<n;i++) {
v = a[i];
j = i;
/* If this element is greater than v,
move it up one */
while ( a[j-1] > v ) {
a[j] = a[j-1]; j = j-1;
if ( j <= 0 ) break;
a[j] = v;
}
}
}
This code was written by Woi Ang (Who is not tribbel)