Question: I am really struggling with getting the counting sort algorithm to work in my practice example. I would love some help with getting this to

I am really struggling with getting the counting sort algorithm to work in my practice example. I would love some help with getting this to run. Ill give you a thumbs up if you can help thank-you

Starter Code:

import java.util.Random; import java.util.Scanner; import java.util.Arrays; import java.util.Collections; import java.util.ArrayList; public class CountingSort { public static int[] prepareData(int[] patients){ /* Data is prepared by inserting random values between 1 and 1000. Data items may be assumed to be unique. Please refer to lab spec for the problem definiton. */ // what is our range? int max = 1000; // create instance of Random class Random randomNum = new Random(); ArrayList list = new ArrayList(); for (int i=0; i

return patients; } public static int[] sortArray(int[] patient_ids){ /* Add your logic below to sort the array.*/

return patient_ids; }

public static void main(String[] args) { System.out.println("Enter the no of patients:"); Scanner scan = new Scanner(System.in); int patients = scan.nextInt(); int[] patient_ids = new int[patients]; int[] patients_populated = prepareData(patient_ids);

/* Implement the sortArray method, so as to get the correct results.*/ int[] sorted_array = sortArray(patients_populated); /* The two lines below will print the output. Do not uncomment these lines. */ System.out.println("Unsorted:\t" + Arrays.toString(patients_populated)); System.out.println("Sorted:\t" + Arrays.toString(sorted_array)); } }

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!