/* Insertion sort for integers */ void insertion( int a[], int n ) /* Pre-condition: a contains n items to be sorted */ { int i, j, v; /* Initially, the first item is considered 'sorted' */ /* i divides a into a sorted region, x= i */ for(i=1;i 0 ) { /* If this element is greater than v, move it up one */ while ( a[j-1] > v ) { a[j] = a[j-1]; j = j-1; } /* Stopped when a[j-1] <= v, so put v at position j */ a[j] = v; } } }