Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions