Question: algorithm: Counting - SORT ( A , n , k ) let B [ 1 : n ] and C [ 0 : k ]
algorithm:
CountingSORT
let : and : be new arrays
for to
for to
now contains the number of elements equal to
for to
now contains the number of elements less than or equal to
Copy to starting from the end of
for downto
to handle duplicate values
return
Your sort takes the array A input and value as arguments. In Java, determine
by asking the array for its length.
Create public static method sort which implements a counting sort for nonnegative integers. It takes two parameters:
an array of integers int input containing the values to be sorted as the first argument do not change the contents of this array
an int maximumValue which is the largest value the input array may contain as the second argument
sort returns a new array of integers containing the sorted output.
Note: you will not be given any values outside the specified range do not check for negative or 'too large' values.
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
