23.1 | ( Generic bubble sort ) 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 comparator) |
23.2 | ( Generic merge sort ) Write the following two generic methods using merge 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 mergeSort(E[] list) public static <E> void mergeSort(E[] list, Comparator comparator) |
| |
23.3 | ( Generic quick sort ) Write the following two generic methods using quick 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 quickSort(E[] list) public static <E> void quickSort(E[] list, Comparator comparator) |
23.4 | ( Improving quick sort ) The quick sort algorithm presented in the book selects the first element in the list as the pivot. Revise it by selecting the medium among the first, middle, and last elements in the list. |
| |
23.5 | ( Generic heap sort ) Write the following two generic methods using heap 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 heapSort(E[] list) public static <E> void heapSort(E[] list, Comparator comparator) |
23.6 | ( Checking order ) Write the following overloaded methods that check whether an array is ordered in ascending order, or descending order. By default, the method checks ascending order. To check descending order, pass false to the ascending argument in the method. public static boolean ordered( int [] list) public static boolean ordered( byte [] list, boolean ascending) public static boolean ordered( double [] list) public static boolean ordered( double [] list, boolean descending) public static <E extends Comparable<E>> boolean ordered(E[] list) public static <E extends Comparable<E>> boolean ordered(E[] list, boolean ascending) public static <E> Boolean ordered(E[] list, Comparator comparator, boolean ascending) |