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

(c) Intuitively, what do you think IS your answer array, a flag notes whether an

ID: 3586353 • Letter: #

Question

(c) Intuitively, what do you think IS your answer array, a flag notes whether any local activity occurs. On a pass, compare adjacent ments, and exchange their values when the first element is greater than the se ment. Set a Boolean flag true if an exchange occurs. At the end of the pass, the element has "bubbled up" to the top of the array. Subsequent passes order the arra back to front. The sort requires at most n 1 passes, with the process terminati flag notes that no swapping occurs during a pass. The upcoming figure illustrates passes of the bubble sort for array arr - (35, 10, 40, 15). The boxe correct location. 17. This exercise develops the bubble-sort algorithm. During multiple passes through cond ele y from terminating if t two d elements are in their 35 10 | 40 | 15 exchange 35 and 10 pass O 10 | 35 | 40 | 15 exchange 10 35 40 15 exchange 40 and 15 15 40 40 is largest in list[0.3] 10 35 pass 1 10 35 15 no exchange 40 10 40 exchange 35 and 15 35 15 10 15 354035 is largest in list[0.2] Implement the template bubble-sort function template void bubblesort (T arrI], int n)

Explanation / Answer

void sort(int *a, int n) {

      bool flag = false;
       for (int i = 0; i < n-1; i++) {
             flag = false;
             for(int j = 0; j < n - 1 - i; j++)
                    if (a[j] > a[j+1]) {
                            flag = true;
                            int tmp = a[j];
                            a[j] = a[j+1];
                            a[j+1] = 5mp
                }

if (!flag)
                     break;;
      }

}

this is a pseudo code for bubble sort! hope you love it