/* * Sort an array of ints using simple insertion sort. */ 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; // I put this statement inside the loop in class // Putting it here is also correct, and saves many unnecessary copies. p++; } }