/* * Sort an array of ints using simple insertion sort. * See our text p. 249 for a generic version that * also uses for() loops. */ public static void insertionSort(int [] a) { int p = 1; while (p < a.length) { int tmp = a[p]; int j = p; while (j > 0 && a[j-1] > tmp) { a[j] = a[j-1]; j--; } a[j] = tmp; p++; } }