Question: (Exercise) Create sortArray2.cpp In this part of the lab, you will write a program that uses a different implementation of selection sort from the one

 (Exercise) Create sortArray2.cpp In this part of the lab, you will

(Exercise) Create sortArray2.cpp In this part of the lab, you will write a program that uses a different implementation of selection sort from the one you chose before: If you had chosen to search for the minimum to traverse the array, now choose the maximum, or If you had chosen to search for the maximum to traverse the array, now choose the minimum. You may choose whether to traverse the array forward or backward. Also, this time you are requested to calculate the number of swaps used to complete sorting of the array. You can write a program starting from the previous one and modify it to sort the array using another selection sort implementation. Once the array is sorted, output the sorted array in a similar way as in the previous exercise. In addition, output "It took ?x> swaps to sort the array." on the console as shown below, where x is the number of swaps carried out by your program. Hint: declare a counter that increments whenever a swap takes place. Sample Runs (user input shown in blue): Enter the size of the array:5 Enter the numbers in the array, separated by a space, and press enter: 46825 The sorted array in ascending order is: 24568 The algorithm selected the minimum for traversing the array. It took 3 swaps to sort the array

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!