Question: Please write in C# In this assignment, you will write a static method that evaluates how close an array is to being sorted in ascending

Please write in C#

In this assignment, you will write a static method that evaluates how close an array is to being sorted in ascending order. Your method should have one parameter, the array of integers to evaluate. For each element of this array, it should count the number of elements that are unsorted with respect to that element: the number of elements that come before it but are larger, plus the number of elements that come after it but are smaller. Your method should return an array containing these counts; specifically, each element of the returned array is the unsorted-values count for the element at the same index in the input array. Finally, if the input array is already completely sorted, your method should print Congratulations, the array is sorted! to the console (as well as returning its result array)

Example:

If the input array contains [12, 9, 18, 1], then the method should return [2, 2, 1, 3], and not print anything to the console. This is because

Element 0, the value 12, has 2 elements that appear after it but are smaller than it (9 and 1)

Element 1, the value 9, has 1 element that appears before it but is larger (the value 12) and 1 element that appears after it but is smaller (the value 1)

Element 2, the value 18, has 1 element that appears after it but is smaller (the value 1)

Element 4, the value 1, has 3 elements that appear before it but are larger (12, 9, and 18

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!