Two "Helper" Methods for Sorting

The following two helper functions allow us to more easily analyze the cost of a sorting algorithm in terms of comparisons and/or exchanges:

// returns true only if v is less than w
private static boolean less(Comparable v, Comparable w) {
   return v.compareTo(w) < 0;
}

// swaps the item in array a[i] at index i with the one at index j
private static void exch(Comparable[] a, int i, int j) {
   Comparable swap = a[i];
   a[i] = a[j];
   a[j] = swap;
}