Bubble Sort You will change the following method bubbleSort() by using generics and complete only one of three bubbleSort() methods. public int[] bubbleSort(int[] list) { //{2, 9, 5, 4, 8, 1, 6} int i, j, temp = 0; for (i = 0; i < list.length - 1; i++) { for (j = 0; j < list.length - 1 ; j++) { if (list[j] > list[j + 1]) { temp = list[j]; list[j] = list[j + 1]; list[j + 1] = temp; } } } return list; } OPTION 1 public static void bubbleSort(E[] list){ //COMPLETE HERE } OPTION 2 public static> void bubbleSort(E[] list){ //COMPLETE HERE }
Bubble Sort You will change the following method bubbleSort() by using generics and complete only one of three bubbleSort() methods.
public int[] bubbleSort(int[] list) {
//{2, 9, 5, 4, 8, 1, 6}
int i, j, temp = 0;
for (i = 0; i < list.length - 1; i++) {
for (j = 0; j < list.length - 1 ; j++) {
if (list[j] > list[j + 1]) {
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}
}
return list;
}
OPTION 1
public static <E> void bubbleSort(E[] list){ //COMPLETE HERE }
OPTION 2
public static<E extends Comparable<E>> void bubbleSort(E[] list){ //COMPLETE HERE }
OPTION 3
public static<E> void bubbleSort(E[] list, Comparator<? super E> comparator){ //COMPLETE HERE }
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images