Run Code Test Cases Assignment Docs Grade 7 Points Status Submitted Exercise Looking Examp Q43842856


![8.4.5: Explore Selection Sort recurs a Sur Leu ali ay ui uie same tillegers. */ 31 public static int[] selectionSort(int[] ar](https://media.cheggcdn.com/media/a48/a48ccf27-e10c-4b8e-99b4-11b66cbedb0c/image.png)
RUN CODE TEST CASES ASSIGNMENT DOCS GRADE MORE 7 points Status: Not Submitted In this exercise, we will be looking at our example code for Selection Sort. However, while we are sorting we will also count the number of swaps taking place, then print them out once the array has been sorted. Add a print statement at the end of the selectionSort method that prints out the number of swaps that took place during the sort. You should not modify the run() method. Hint: where are items compared? Try writing out the steps in the algorithm on paper to help 8.4.5: Explore Selection Sort 1 import java.util.Arrays; 3 public class SelectionSort extends Console Program 4-{ public void run() int[] array1 = {9, 8, 7, 6, 5, 4, 3, 2, 1); int[] array2 = {5, 6, 4, 8, 9, 7, 3, 1, 2); System.out.print(“First array: “); System.out.println(Arrays.toString(array1)); System.out.print(“Second array: “); System.out.println(Arrays.toString(array2)); System.out.println(); // sort first array selection Sort(array1); // sort second array selection Sort(array2); System.out.print(“First array sorted: “); System.out.println(Arrays.toString(array1)); System.out.print(“Second array sorted: “); System.out.println(Arrays.toString(array2)); 27 – * Selection sort takes in an array of integers and · returns a sorted array of the same integers. 29 30 * 31 public static int Il selectionSort(int[] arr) Algorithms and Recursion – 0 DO 0 5 8.4.5: Explore Selection Sort recurs a Sur Leu ali ay ui uie same tillegers. */ 31 public static int[] selectionSort(int[] arr) int currentMinIndex; for (int i = 0; i < arr. length -1; i++) 35 – 36 currentMinIndex = i; for (int j = i + 1; j < arr.length; j++) 38 – if(arr[j] < arr[currentMinIndex]) 40 – currentMinIndex – j; 45 // swap numbers if needed if (i l= currentMinIndex) int temp = arr[currentMinIndex]; arr[currentMinIndex] = arr[i]; arr[i] = temp; 1/ Print out the number of swaps that took place here // before returning arr return arr; gorithms and Recursion ims and Recursion – 0 3 – OOOOOO O Type here to search Show transcribed image text RUN CODE TEST CASES ASSIGNMENT DOCS GRADE MORE 7 points Status: Not Submitted In this exercise, we will be looking at our example code for Selection Sort. However, while we are sorting we will also count the number of swaps taking place, then print them out once the array has been sorted. Add a print statement at the end of the selectionSort method that prints out the number of swaps that took place during the sort. You should not modify the run() method. Hint: where are items compared? Try writing out the steps in the algorithm on paper to help
8.4.5: Explore Selection Sort 1 import java.util.Arrays; 3 public class SelectionSort extends Console Program 4-{ public void run() int[] array1 = {9, 8, 7, 6, 5, 4, 3, 2, 1); int[] array2 = {5, 6, 4, 8, 9, 7, 3, 1, 2); System.out.print(“First array: “); System.out.println(Arrays.toString(array1)); System.out.print(“Second array: “); System.out.println(Arrays.toString(array2)); System.out.println(); // sort first array selection Sort(array1); // sort second array selection Sort(array2); System.out.print(“First array sorted: “); System.out.println(Arrays.toString(array1)); System.out.print(“Second array sorted: “); System.out.println(Arrays.toString(array2)); 27 – * Selection sort takes in an array of integers and · returns a sorted array of the same integers. 29 30 * 31 public static int Il selectionSort(int[] arr) Algorithms and Recursion – 0 DO 0 5
8.4.5: Explore Selection Sort recurs a Sur Leu ali ay ui uie same tillegers. */ 31 public static int[] selectionSort(int[] arr) int currentMinIndex; for (int i = 0; i
Expert Answer
Answer to RUN CODE TEST CASES ASSIGNMENT DOCS GRADE MORE 7 points Status: Not Submitted In this exercise, we will be looking at ou…
Related