Question: public class Heap { private int currentSize; private int[] heapArray; // Constructors public Heap() { setCurrentSize(0); heapArray = new int[1]; } public Heap(int capacity) {

 public class Heap { private int currentSize; private int[] heapArray; //

public class Heap { private int currentSize; private int[] heapArray; // Constructors public Heap() { setCurrentSize(0); heapArray = new int[1]; } public Heap(int capacity) { setCurrentSize(0); heapArray = new int[capacity + 1]; } // Heap Operations public int[] buildHeap(int[] array) { // Builds the heap from an array that you have provided currentSize = array.length; heapArray = new int[(currentSize + 1)]; for (int i = 0; i 0; i--) { percolateDown(i); } return heapArray; } private void percolateDown(int hole) { // Organizes the elements of the heap and percolate down the elements for not violating heap properties int child; int tmp = heapArray[hole]; for( ; hole * 2

// IMPLEMENT THIS METHOD // ... } public int getHeight() { // Returns the height of the binary min heap // IMPLEMENT THIS METHOD // ... } public void insert(int value) { // Inserts an integer element to the binary min heap // IMPLEMENT THIS METHOD // ... // percolateUp (value, hole); }

private void percolateUp(int value, int hole) { // Organizes the elements of the heap and percolate up the elements for not violating heap properties // IMPLEMENT THIS METHOD // ... }

private boolean search(int value) { // Searches the heap for if the given value is present or not, returns TRUE if value is present, FALSE otherwise // IMPLEMENT THIS METHOD // ... } // Helper Methods public boolean isEmpty() { return currentSize == 0; } public void makeEmpty() { currentSize = 0; } private void enlargeArray(int newSize) { // Enlarges array to the new size int[] old = heapArray; heapArray = new int[newSize]; for( int i = 1; i

public void setCurrentSize(int currentSize) { this.currentSize = currentSize; }

public int[] getHeapArray() { return heapArray; }

public void setHeapArray(int[] heapArray) { this.heapArray = heapArray; } }

I have 70 minutes use JAVA please help !!!!

Download Heap.java and Main.java from Blackboard. Create a Java Project; put all downloaded Java files in the same package. In this assignment you are already given an array implementation of a Heap. You need to modify both Heap.java and Main.java files. 1. Instantiate a new Heap object in the main function. [5 pts] 2. Heap class has a buildHeap (int[] array) method which builds a binary min heap from the given array arrayA[]. Use that method to build your heap. [10 pts] 3. Print the elements using the method printHeap () - [5 pts] 4. Implement getMinvalue () method which returns the minimum element of the heap. Use it and print the minimum value. (10 pts] 5. Implement getHeight () method which returns the height of the heap. Use it and print the height of the heap. (10 pts] 6. Implement the insert(int value) method in Heap class which inserts the given value to the heap. You can use any value to test whether the method works properly or not. (20 pts] 6.1. You will need to implement percolateup (int value, int hole) helper method for insert method to work. It moves up the hole into the correct position without violating the heap order property. [25 pts] 7. Print the heap elements using printHeap () again. [5 pts] 8. Implement a search(int value) method which searches the given element and returns TRUE if the element is found in the heap, FALSE otherwise. Your method should use heap properties for its benefit. [10 pts]

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!