Question: 1. Define a Java method with the following header: public static void bubbleSort (double 1 1ist) This method applies bubble sort to arrange the elements
1. Define a Java method with the following header: public static void bubbleSort (double 1 1ist) This method applies bubble sort to arrange the elements of an array into ascending order. Note that this method does not return anything; it modifies the array parameter directly! Bubble sort works by making several passes through an array. On each pass, successive neighboring pairs are compared. If a pair is in decreasing order (i.e., one element is larger than the following element), the values are swapped; otherwise, the values remain unchanged. The technique is called a bubble sort or sinking sort because the smaller values gradually "bubble" their way to the top and the larger values sink to the bottom. The algorithm can be described as follows: boolean changed true; do changed false; for (int j = 0; j listj 1]) // add code to swap list j] with list11 changed = true; while (changed) Clearly, the list is in increasing order when the loop terminates. It is easy to show that the do loop executes at most (list.length-1) times. Write a Java program that creates a double array with the initial values (6.0,4.4, 1.9, 2.9, 3.4, 2.9, 3.5) and calls bubblesort()to re-order its elements. For clarity, add print statements to your bubbleSort() method to display the current arrangement of the array after every loop iteration
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
