Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

Provide the major organic product in the reaction below.

Answered: 1 week ago

Question

25.0 m C B A 52.0 m 65.0 m

Answered: 1 week ago

Question

6. Why is investment spending unstable? LO30.4

Answered: 1 week ago