Define a function that sorts an array of distinct integers


Problem

In C++, without the use of any dynamic array or vector

Define a function that sorts an array of distinct integers using the following algorithm:

For each value of the array the function counts the number of values that are smaller than the value to identify the index of the value in the sorted array. For example if the current value is 10 and there are 3 values smaller than 10 in the array, the index of value 10 in the sorted array will be 3. The function then stores that value in the identified index, starting from the end of the array. In other words, this function stores the sorted list of values after the last value of the list. For example, if the input array is: [1, 10, 3, 6, 4, 0, -1], the array after sorting in ascending order will be [1, 10, 3, 6, 4, 0, -1, -1, 0, 1, 3, 4, 6, 10]. It is assumed that the size of the input array is enough to hold the sorted list after the current values of the list.

Your function should be able to sort the array in ascending or descending order. An argument will be passed to the function that specifies if the array should be sorted ascendingly or desceendingly. The default order is ascending.

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Define a function that sorts an array of distinct integers
Reference No:- TGS03354388

Expected delivery within 24 Hours