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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started