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](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66ef8930ee250_25666ef89303b286.jpg)
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
Get step-by-step solutions from verified subject matter experts
