Menu

Write Function Named Bubble Int Int N Takes Array N Elements Function Goes Array Compares Q43854708

Write a function named bubble(int a[], int n) that takes an array with n elements. The function goes through the array and co

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. Show transcribed image text 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.

Expert Answer


Answer to Write a function named bubble(int a[], int n) that takes an array with n elements. The function goes through the array a…

OR