Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How does eBay offer value to its customers?

Answered: 1 week ago