Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 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

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

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

exercise 12-4 special order decision

Answered: 1 week ago

Question

Describe a persuasive message.

Answered: 1 week ago

Question

Identify and use the five steps for conducting research.

Answered: 1 week ago

Question

List the goals of a persuasive message.

Answered: 1 week ago