Question: public class MaxHeap

public class MaxHeapextends Comparablesuper T>> implements HeapInterface { private T[] backingArray; private int size;   public MaxHeap() { backingArray = (T[]) new Comparable[INITIAL_CAPACITY]; } /**  * Creates a properly ordered heap from a set of initial values.  *  * You must use the Build Heap algorithm that was taught in lecture! Simply  * adding the data one by one using the add method will not get any credit.  *  * The initial array before the Build Heap algorithm takes place should  * contain the data in the same order as it appears in the ArrayList.  *  * The {@code backingArray} should have capacity 2n + 1 where n is the  * number of data in the passed in ArrayList (not INITIAL_CAPACITY from  * the interface). Index 0 should remain empty, indices 1 to n should  * contain the data in proper order, and the rest of the indices should  * be empty.  *  * @param data a list of data to initialize the heap with  * @throws IllegalArgumentException if data or any element in data is null  */  public MaxHeap(ArrayList data) { // code } 

..

..

.

}

public interface HeapInterfaceextends Comparablesuper T>> { public static final int INITIAL_CAPACITY = 16; /**  * Adds an item to the heap. If the backing array is full and you're trying  * to add a new item, then double its capacity. The data passed in will not  * be in the heap. Therefore, there will be no duplicates.  *  * @throws IllegalArgumentException if the item is null  * @param item the item to be added to the heap  */  public void add(T item); /**  * Removes and returns the first item of the heap. Null out all elements not  * existing in the heap after this operation. Do not decrease the capacity  * of the backing array.  *  * @throws java.util.NoSuchElementException if the heap is empty  * @return the item removed  */  public T remove(); /**  * Returns if the heap is empty or not.  * @return a boolean representing if the heap is empty  */  public boolean isEmpty(); /**  * Returns the size of the heap.  * @return the size of the heap  */  public int size(); /**  * Clears the heap and returns array to starting capacity.  */  public void clear(); /**  * Used for grading purposes only.  *  * DO NOT USE OR EDIT THIS METHOD!  *  * @return the backing array  */  public Comparable[] getBackingArray(); } 

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!