Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you help me with getting this HeapSort program to run correctly because I am struggling. I will give a thumbs up for anybody that

Can you help me with getting this HeapSort program to run correctly because I am struggling. I will give a thumbs up for anybody that can help out.

Starter Code:

import java.util.Random; import java.util.Scanner; import java.util.Arrays; import java.util.Collections; import java.util.ArrayList; public class HeapSort { public static int[] prepareData(int[] data){ /* Data is prepared by inserting random values between 1 and data.length. Data items may be assumed to be unique. Please refer to lab spec for the problem definiton. */ ArrayList list = new ArrayList(); for (int i=0; i< data.length; i++) { list.add(i); } Collections.shuffle(list); for (int i=0; i < data.length; i++) { data[i] = list.get(i); } return data; }

public static int[] heapify(int[] data){ /* Add your logic here */ // make the call to fix it from here. return data; } public static int[] sortArray(int[] data){ /* Add your logic here */

return data; } public static void main(String[] args) { /* Assume binary tree, either complete or atmost complete. But not in-complete. */ System.out.println("Enter the no of elements:"); Random rand = new Random(); Scanner scan = new Scanner(System.in); int count = scan.nextInt(); int[] raw_data = new int[count]; int[] raw_data_populated = prepareData(raw_data); System.out.println("Unsorted Array: " + Arrays.toString(raw_data_populated));

/* The line below will print the output. Do not uncomment this lines. */ sortArray(raw_data_populated); System.out.println("Sorted Array: " + Arrays.toString(raw_data_populated));

} }

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

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions

Question

How does selection differ from recruitment ?

Answered: 1 week ago