Question: C++ Write a function named bubble(int a[], int n) that takes an array with n elements. The function goes through the array and compares consecutive

 C++ Write a function named bubble(int a[], int n) that takes

C++

Write a function named bubble(int a[], int n) that takes an array with n elements. The function goes through the array and compares consecutive elements, exchanging them if they are out of order: if a[i] > a[i+1] exchange these two array elements. Note, you cannot exchange two things by doing: x=y: y=x; (Why not?) You can exchange two values like this: x_old = x; x=y: y=x_old; OR X_new = y; y=x x=x_new; Write a main program, include: int b[] = {20, 50, 10, 90, 70, 40, 30, 20, 80, 60); Call bubble on array b and print b both before and after the call. Be careful that in the function when you access a[i+1] you don't run off the end of the array

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!