Question: Answer in Java! In this project I want you to add a method called deleteHeap, which will take this heap as parameter and delete data

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

public static void main(String[] args) {

Integer[]data = {56,8,13,41,5,104,11,39,57,62,90,60};

Integer[] heap = CreateHeap(data);

for (int j=0; j<12; j++)

System.out.print(heap[j]+ " ");

return;

}

public static Integer[] CreateHeap(Integer[]data)

{ Integer[] heap = new Integer[12];

heap[0]=data[0];

for(int i=1; i<12; i++)

{ //insert data[n]

heap[i]=data[i];

//reheap if necessary

int n=i;

while((n-1)/2>=0 && heap[(n-1)/2]

{ Integer temp=heap[(n-1)/2];

heap[(n-1)/2]=heap[n];

heap[n]=temp;

n=(n-1)/2;

}

}

return heap;

}

}

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!