Part A) Perform a bubble-sort (by hand, do not code) on the following array: 44,
ID: 3532125 • Letter: P
Question
Part A) Perform a bubble-sort (by hand, do not code) on the following array: 44, 33, 99, 77, 22, 55, 11 When finished, the array should be in ascending order. Display the content of each element of the array following each completed traversal of the array. A traversal is one pass through the array, having looked at all elements. Do not display the contents of the array after each element swap. How many traversals did it take to sort the array? Part B) Consider the following Java program: public static void main(String[] args) { int a[] = {5, 16, 3, 9, 22, 13, 77, 99, 12}; int i, j, m, t; int n = a.length; for (i = 0; i < n - 1; i++) { m = i; for (j = i + 1; j < n; j++){ if (a[j] < a[m]){ m = j; } } if (m != i) { t = a[i]; a[i] = a[m]; a[m] = t; } } } Briefly describe what this Java program does? (one sentence should suffice) I want to display the contents of the array following each completed traversal of the array. Here is the Java code to do that: for (int k = 0; k < a.length; k++) { System.out.print(a[k] + " "); } System.out.println(); Where should I insert this code into the Java segment (above), so that I get the display I want?
Explanation / Answer
Put that code after a[m] = t;