Question: program in c++~ DESCRIPTION OF A SORTING ALGORITHM Suppose we want to sort n integers of an array A in ascending order using the algorithm

program in c++~

program in c++~ DESCRIPTION OF A SORTING ALGORITHM Suppose we want tosort n integers of an array A in ascending order using the

DESCRIPTION OF A SORTING ALGORITHM Suppose we want to sort n integers of an array A in ascending order using the algorithm described below. For the following explanation given below, assume that the number of integers is n>5 and that there are no duplicates in the array. A is an array with n integers. - We place the largest of the array A of n integers into A[n1] by comparing pairs of numbers: we compare A[0] with A[1] and if A[0]>A[1] then A[0] and A[1] are swapped we compare A[1] with A[2] and if A[1]>A[2], then A[1] and A[2] are swapped we continue comparing in pairs we compare A[n2] with A[n1] and if A[n2]>A[n1], then A[n2] and A[n1] are swapped - We place the smallest of the first n1 integers into A[0] by comparing pairs of numbers "in the opposite direction" from the previous pass: we compare A[n2] with A[n3] and if A[n2]A[2] then A[1] and A[2] are swapped we compare A[2] with A[3] and if A[2]>A[3], then A[2] and A[3] are swapped we continue comparing in pairs we compare A[n3] with A[n2] and if A[n3]>A[n2], then A[n3] and A[n2] are swapped - We place the smallest of the integers from A[1] up to and including A[n3] into A[1] by comparing pairs of numbers "in the opposite direction" from the previous pass: we compare A[n3] with A[n4] and if A[n3]5. For your assignment and in general, do not assume that there are no duplicates. Duplicates are allowed in the array A. I just made those two simplifications to explain the algorithm above. 1. Implement the algorithm described in the previous section and use the function prototype voidsort(intA[],intn); You may overload the function sort but you must still use the function prototype above to call the overloaded function. Do not keep track of the swaps. No need to keep a Boolean variable that would help you optimize whenever any integers were not swapped in a pass. 2. Now using the rand() library function, generate an array of 19 random integers in the range 0

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!