Question: Given the bubbleSort() function: void bubbleSort(int arr[], int length) { } // Bubble largest number toward the right for (int i= length-1; i >

 Given the bubbleSort() function: void bubbleSort(int arr[], int length) { } //  

Given the bubbleSort() function: void bubbleSort(int arr[], int length) { } // Bubble largest number toward the right for (int i= length-1; i > 0; i--) for (int j = 0; j arr[j+1]) { } // Swap the numbers int temp = arr[j+1]; arr[j+1] = arr[j]; arr[j] = temp; When the function is called, arr[] has values (5, 4, 1, 3, 5, 2), and length is 6. Based on this info, please answer following questions: 1. What are expected values for arr[] when the function finishes? 2. When variable i is 3 and variable j is 1, before executing the if block, what are the values of arr[] ? 3. At the time the function finishes, how many times has the "swap" happened?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!