Question: Java-- Create a class called BubbleSort that contains the following method: public static void sort(int[] data) Which implements the bubble sort. The bubble sort uses

Java--

Create a class called BubbleSort that contains the following method:

public static void sort(int[] data) Which implements the bubble sort.

The bubble sort uses nested loops to make repeated passes through the array. Each pass compares successive pairs of elements. If a pair is in increasing order (or the values are equal), the bubble sort leaves the values as they are. If a pair is in decreasing order, the bubble sort swaps their values in the array. The first pass compares the first two element of the array and swaps their values if necessary. It then compares the second and third element in the array. The end of this pass compares the last two elements in the array and swaps them if necessary. After one pass, the largest element will be in the last index. After two passes, the largest two elements will be in the last two indices. The passing through the array is repeated until no swaps are need, indicating the array is sorted.

Create a second class called BubbleSortTest that contains the main method, and tests the BubbleSort.sort method. The test class should create an unordered array of 10 random ints. It should print the unordered array, call the sort method, and then print the sorted array.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!