Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN JAVA Write a generic bubble sort method. The bubble sort sorts the elements u

ID: 3836970 • Letter: I

Question

IN JAVA

Write a generic bubble sort method. The bubble sort sorts the elements using the Comparable interface. The method header is as follows.

public static <E extends Comparable<E>> void bubblesort(E[] list)

The main method should declare an array of Double values, sort the array, and print out the array. It should look something like the following.

public static void main(String[] args) {

Double[] list = {2.1, 3.5, 2, 5.5, 6.1, 1.3, -2.0, 3.1, 14.5, 12.8};

           bubbleSort(list);

           for (int i = 0; i < list.length; i++)

                System.out.print(list[i] + " ");

Explanation / Answer

public class GenericBubbleSort { public static void main(String[] args) { Double[] list = {2.1, 3.5, 2, 5.5, 6.1, 1.3, -2.0, 3.1, 14.5, 12.8}; bubbleSort(list); for (int i = 0; i