Question: The program is the same as shown at the end of the Merge sort section, with the following changes: Numbers are entered by a user
The program is the same as shown at the end of the Merge sort section, with the following changes:
Numbers are entered by a user in a separate helper function, ReadNums instead of defining a specific array in main The first number is how many integers to be sorted, and the rest are the integers.
Output of the array has been moved to the helper function PrintNums
An output has been added to MergeSort showing the indices that will be passed to the recursive function calls.
Add code to the merge sort algorithm to count the number of comparisons performed.
Add code at the end of main that outputs "comparisons: followed by the number of comparisons performed Ex: "comparisons:
Hint: Use a global variable to count the comparisons.
Note: Take special care to look at the output of each test to better understand the merge sort algorithm.
Ex: When the input is:
the output is:
unsorted:
sorted:
comparisons:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
