Question: 1. What is the output? 2. Rewrite the program above and make the Bubble sort a Function (write the prototype, call and header/function copy/paste the

1. What is the output?

2. Rewrite the program above and make the Bubble sort a Function (write the prototype, call and header/function copy/paste the bubble sort into the function and make needed adjustments). Make the for loops a second function (with prototype, call and header). Call them from main( ) as well

int main() { int i = , j , y = 0 tmp = 0; int a[] = { 8,1,6,2,4 }; cout << "original array = "; for (int d : a) { cout << " a[" << y << "] =" << d; y++; } for (j = 1; j <= y; j++) { for (i = 0; i < y - 1; i++) { if (a[i] < a[i + 1]) { tmp = a[i]; a[i] = a[i + 1]; a[i + 1] = tmp; } } } cout << " sorted array = "; for (int d : a) cout << " a[ ] = " << d; return 0; }

c++

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 Databases Questions!