Menu

[Solved]6 4 Points Following Code Insertion Sort Modified Print Sorted Component Array Sort Output Q37269584

6. (4 points) The following code for insertion sort has been modified to print out the sorted component of the array during t

6. (4 points) The following code for insertion sort has been modified to print out the sorted component of the array during the sort. What will be the output of running the main method of the following code? Try to trace by hand and then verify by executing the code public class Insertion public static void sort(String[] a) [ int n-a.length; for (int i 1; i < n; i++) { for (int j i; j > 0; j-) { if (alj-1].compareTo exch(a, j-1, j); else break; // print sorted component of array; for (int k 0; k <= i; k++) { Stdout.print(a[k] + “”); Stdout.printlnO; private static void exch(String[] a, int i, int j) f a[i] String swap a[1] = a[j]; a[j] swap ; public static void main(String[] args) String[] data-f”it” , “was”, “the”, “best”, “of”,”times”,”it”,”was”; sort (data); Show transcribed image text 6. (4 points) The following code for insertion sort has been modified to print out the sorted component of the array during the sort. What will be the output of running the main method of the following code? Try to trace by hand and then verify by executing the code public class Insertion public static void sort(String[] a) [ int n-a.length; for (int i 1; i 0; j-) { if (alj-1].compareTo exch(a, j-1, j); else break; // print sorted component of array; for (int k 0; k

Expert Answer


Answer to 6. (4 points) The following code for insertion sort has been modified to print out the sorted component of the array dur… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *