Question: Can someone help me answer this C++ question B. Sorting Arrays Sort the first array (call it arrayA) in ascending order. Sort the second array

Can someone help me answer this C++ question

B. Sorting Arrays Sort the first array (call it arrayA) in ascending order. Sort the second array (call it arrayB) in descending order.

Have a function sortArr that takes in an array, array length, and a boolean value to indicate whether to sort in ascending or descending order. Function sortArr needs to call another function, call it swap2, for performing the array element swap operations required for sorting.

You should call sortArr twice from main to sort each array.

Many sorting algorithms exist. A very simple one (though quite inefficient) is the Bubble Sort algorithm. The Bubble Sort implementation is given below and can be used as starter code:

for(int i = length-1; i>0; i--)

{

for(int j = 0; j < i; j++)

{

if(arr[j]>arr[j+1]){

temp = arr[j];

arr[j] = arr[j+1];

arr[j+1] = temp;

}

}

}// Ascending or descending implementation?

Thanks so much!!!

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!