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