/*
  Write the following two generic methods using bubble sort. The first method
  sorts the elements using the Comparable interface and the second uses the
  Comparator interface.

  public static <E extends Comparable<E>> void bubbleSort(E[] list)
  public static <E> void bubbleSort(E[] list, Comparator<? super E> comparator)
*/

import java.util.Comparator;

public class E23_01 {
  public static void main(String[] args) {
    Integer[] list = {16, 2, 10, 18, 15, -20, 52, -100, 10001};
    Integer[] copy1 = new Integer[list.length];
    Integer[] copy2 = new Integer[list.length];
    System.arraycopy(list, 0, copy1, 0, list.length);
    System.arraycopy(list, 0, copy2, 0, list.length);

    bubbleSort(copy1);
    System.out.println("bubbleSort (Comparable):");
    displayList(copy1);

    bubbleSort(copy2, new Comparator<Integer>(){
      @Override
      public int compare(Integer o1, Integer o2) {
        if (o1.compareTo(o2) > 0) {
          return -1;
        } else if (o1.compareTo(o2) < 0) {
          return 1;
        }
        return 0;
      }
    });
    System.out.println("bubbleSort (Comparator - descending):");
    displayList(copy2);
  }

  public static <E extends Comparable> void bubbleSort(E[] list) {
    boolean changed;
    do {
      changed = false;
      for (int i = 0; i < list.length - 1; i++) {
        if (list[i + 1].compareTo(list[i]) < 0) {
          E temp = list[i];
          list[i] = list[i + 1];
          list[i + 1] = temp;
          changed = true;
        }
      }
    } while (changed);
  }

  public static <E> void bubbleSort(E[] list, Comparator<? super E> comparator) {
    boolean changed;
    do {
      changed = false;
      for (int i = 0; i < list.length - 1; i++) {
        if (comparator.compare(list[i + 1], list[i]) < 0) {
          E temp = list[i];
          list[i] = list[i + 1];
          list[i + 1] = temp;
          changed = true;
        }
      }
    } while (changed);
  }

  public static <E> void displayList(E[] list) {
    for (int i = 0; i < list.length; i++) {
      System.out.print(list[i] + " ");
    }
    System.out.println();
  }
}

@@ -1202,16 +1202,19 @@
 mparable
+%3CE%3E
 %3E void b
@@ -1244,311 +1244,52 @@
    b
-oolean changed;%0A    do %7B%0A      changed = false;%0A      for (int i = 0; i %3C list.length - 1; i++) %7B%0A        if (list%5Bi + 1%5D.compareTo(list%5Bi%5D) %3C 0) %7B%0A          E temp = list%5Bi%5D;%0A          list%5Bi%5D = list%5Bi + 1%5D;%0A          list%5Bi + 1%5D = temp;%0A          changed = true;%0A        %7D%0A      %7D%0A    %7D while (changed
+ubbleSort(list, new AscendingComparator%3CE%3E()
 );%0A 
@@ -1329,32 +1329,36 @@
 leSort(E%5B%5D list,
+%0A   
  Comparator%3C? su
@@ -1871,11 +1871,308 @@
 n();%0A  %7D
+%0A%0A  private static class AscendingComparator%3CE extends Comparable%3CE%3E%3E%0A    implements Comparator%3CE%3E %7B%0A    @Override%0A    public int compare(E o1, E o2) %7B%0A      if (o1.compareTo(o2) %3C 0) %7B%0A        return -1;%0A      %7D else if (o1.compareTo(o2) %3E 0) %7B%0A        return 1;%0A      %7D%0A      return 0;%0A    %7D%0A  %7D
 %0A%7D%0A

Make bubbleSort with list argument use the Comparator version with an ascending comparator object. Fix references to raw types.