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

EXERCISE 1: Implement Bubble Sort in Java Add a new class called BubbleSort1 to

ID: 3873268 • Letter: E

Question

EXERCISE 1: Implement Bubble Sort in Java Add a new class called BubbleSort1 to your Java project and paste in the skeleton code below. mplement the sort method according to the Bubble Sort algorithm described previously. Hint: This will require writing a nested loop, one loop inside another loop, with a comparison/swap operation being performed inside the inner loop. Your method should also count how many comparisons are made and return this count value when the array has finished being sorted. Test your algorithm using 10 random integers in the range 0-100. Your sort) method should print out the array after each pass of the algorithm, so you can verify the correct operation of your code step by step. public class BubbleSort1 // Sorts integer array in ascending order using Bubble Sort algorithm // Returns total number of basic steps (comparisons) needed to complete the sort public static long sort (int[) items) ( // add your code here // Prints contents of integer array to standard output public static void print (int[] items) /I add your code here // Swap elements i and j of an array public static void swap(int[] items, int i, intj) // add your code here public static void main(String args[]) ( // Make a test array of integers and sort them and carefully // examine output to check algorithm is functioning correctly

Explanation / Answer

// Java program for implementation of Bubble Sort class BubbleSort1 { public static long sort(int items[]) { // taking length and initializing count for counting comparisions int len = items.length, count = 0;    // looping through each element for (int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote