Question: Heapinterface code: import java.util.NoSuchElementException; / * * * d - Heap interface. * * @param Generic type * / public interface HeapInterface > { /
Heapinterface code:
import java.util.NoSuchElementException;
dHeap 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 addT 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
@SuppressWarningsunchecked
public dHeap
TODO
Initializes a binary max heap with a given initial capacity.
@param heapSize The initial capacity of the heap.
@SuppressWarningsunchecked
public dHeapint heapSize
TODO
Initializes a dary 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.
@SuppressWarningsunchecked
public dHeapint d int heapSize, boolean isMaxHeap throws IllegalArgumentException
TODO
@Override
public int size
TODO
return ;
@Override
public T remove throws NoSuchElementException
TODO
return null;
@Override
public void addT item throws NullPointerException
TODO
@SuppressWarningsunchecked
@Override
public void clear
TODO
@Override
public T element throws NoSuchElementException
TODO
return null;
private int parentint index
TODO
return ;
private void percolateUpint index
TODO
private void percolateDownint index
TODO
@SuppressWarningsunchecked
private void resize
TODO
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
