Question: Heapinterface code: import java.util.NoSuchElementException; / * * * d - Heap interface. * * @param Generic type * / public interface HeapInterface > { /

Heapinterface code:
import java.util.NoSuchElementException;
/**
* d-Heap interface.
*
* @param Generic type
*/
public interface HeapInterface>{
/**
* Returns the number of elements stored in the heap.
*
* @return The number of elements stored in the heap.
*/
int size();
/**
* Removes and returns the element at the root. If the heap is empty, then this
* method throws a NoSuchElementException.
*
* @return The element at the root stored in the heap.
* @throws java.util.NoSuchElementException if the heap is empty
*/
T remove() throws NoSuchElementException;
/**
* Adds the specified element to the heap; o cannot be null. Resizes the storage
* if full.
*
* @param item The element to add.
* @throws NullPointerException if o is null.
*/
void add(T item) throws NullPointerException;
/**
* Clears all the items in the heap
* Heap will be empty after this call returns
*/
public void clear();
/**
* Retrieves, but does not remove, the element at the root.
*
* @return item at the root of the heap
* @throws NoSuchElementException - if this heap is empty
*/
public T element() throws NoSuchElementException;
}
dHeap code:
import java.util.Arrays;
import java.util.NoSuchElementException;
/**
* Title: dHeap Description: This program creates a Heap with d branching factor
*
* @author TODO
* @since TODO
*
* @param the type of elements held in this collection
*/
public class dHeap> implements HeapInterface {
private T[] heap; // backing array
private int d; // branching factor
private int nelems; // number of elements
private boolean isMaxHeap; // indicates whether heap is max or min
/**
* Initializes a binary max heap with capacity =10
*/
@SuppressWarnings("unchecked")
public dHeap(){
// TODO
}
/**
* Initializes a binary max heap with a given initial capacity.
*
* @param heapSize The initial capacity of the heap.
*/
@SuppressWarnings("unchecked")
public dHeap(int heapSize){
// TODO
}
/**
* Initializes a d-ary heap (with a given value for d), with a given initial
* capacity.
*
* @param d The number of child nodes each node in the heap should have.
* @param heapSize The initial capacity of the heap.
* @param isMaxHeap indicates whether the heap should be max or min
* @throws IllegalArgumentException if d is less than one.
*/
@SuppressWarnings("unchecked")
public dHeap(int d, int heapSize, boolean isMaxHeap) throws IllegalArgumentException {
// TODO
}
@Override
public int size(){
// TODO
return 0;
}
@Override
public T remove() throws NoSuchElementException {
// TODO
return null;
}
@Override
public void add(T item) throws NullPointerException {
// TODO
}
@SuppressWarnings("unchecked")
@Override
public void clear(){
// TODO
}
@Override
public T element() throws NoSuchElementException {
// TODO
return null;
}
private int parent(int index){
// TODO
return 0;
}
private void percolateUp(int index){
// TODO
}
private void percolateDown(int index){
// TODO
}
@SuppressWarnings("unchecked")
private void resize(){
// TODO
}
}

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 Programming Questions!