Question: HELP IN JAVA: In this project I want you to add a method called deleteHeap, which will take this heap as parameter and delete data

HELP IN JAVA:

In this project I want you to add a method called deleteHeap, which will take this heap as parameter and delete data from it until there is none left, storing the sorted data into an array, which is then passed back to main. Main will output this array, demonstrating that it is sorted.

What I have so far:

public class H10 { public static void main(String[] args) { int []A = {56,8,13,41,5,104,11,39,57,62,90,60}; int []Heap = CreateHeap(A); printArray(Heap); deleteHeap(Heap); printArray(Heap); } static void printArray(int arr[]) { int n = arr.length; for (int i=0; i

public static int[] CreateHeap(int[]A) { int[] Heap; Heap = new int[12]; Heap[0] = A[0]; for(int i = 1; i < 12; i++){ Heap[i] = A[i]; int n = i;

while ((n-1)/2 >= 0 && Heap[(n-1)/2] < Heap[n]) { int temp = Heap[(n-1)/2]; Heap[(n-1)/2] = Heap[n]; Heap[n] = temp; n = (n-1)/2; } } return Heap; } public static int[] deleteHeap(int A[]) { int[] newArr; newArr = new int[12]; CreateHeap(A); int n = A.length-1; for(int i=n; i>0; i--){ int temp = A[0]; A[0] = newArr[i]; newArr[i] = temp; n = n-1; deleteHeap(A); } return newArr; }

}

need help with the deleteHeap method the ouput should be a new array sorted from least to greatest. The contents in the heap should now be deleted after it is passed through the method.

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!