Question
I am having trouble writing a binary sort algorithm. I would love some help to figure out this practice problem. The starter code is listed
I am having trouble writing a binary sort algorithm. I would love some help to figure out this practice problem. The starter code is listed below. I will give a thumbs up if you can help
Starter Code:
import java.util.Random; import java.util.Scanner; import java.util.Arrays; import java.util.Collections; import java.util.ArrayList; public class BinarySort { 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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started