import java.util.Comparator; class BubbleSort { public static void swap(E[] arr, int i, int j) { E temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } // public static void sort(int[] data) { // // we "bubble up" n times // for (int numSorted = 0; numSorted < data.length; numSorted++) { // // "bubble" the largest element to the top of the unsorted pile // for (int i = 1; i < data.length; i++) { // if (data[i-1] > data[i]) { // swap(data, i-1, i); // } // } // } // } public static void sortGeneric(E[] data, Comparator c) { // we "bubble up" n times for (int numSorted = 0; numSorted < data.length; numSorted++) { // "bubble" the largest element to the top of the unsorted pile for (int i = 1; i < data.length; i++) { if (c.compare(data[i-1], data[i]) > 0) { swap(data, i-1, i); } } } } }