Question: New Java project The bubble sort algorithm shown in this chapter is less efficient than it can be. If a pass is made throught the
New Java project
The bubble sort algorithm shown in this chapter is less efficient than it can be. If a pass is made throught the list without exchanging any elements, this means that the list is sorted and there is no reason to continue. Modify this algorithm so that it will stop as soon as it recognizes that the list is sorted.
Modify the below code
import java.util.Arrays;
public class Base_A07Q1 { /** * Program entry point for bubblesort testing. * @param args Argument list. */ public static void main(String[] args) { Integer[] data = {72, 54, 31, 39, 53, 9, 81, 73, 98, 99}; System.out.println("Before: " + Arrays.toString(data)); bubbleSort(data); System.out.println("After: " + Arrays.toString(data)); } /** * Swaps to elements in an array. Used by various sorting algorithms. * * @param data the array in which the elements are swapped * @param index1 the index of the first element to be swapped * @param index2 the index of the second element to be swapped */ private static
****NOTE PLEASE MODIFY THE EXSISTING CODE, and RUN IT ********
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
