Class Heap<E>
java.lang.Object
Heap<E>
- Type Parameters:
E- Type of elements stored in this heap
- All Implemented Interfaces:
HeapInterface<E>
A generic heap that stores elements in a a generic array.
-
Field Summary
Fields inherited from interface HeapInterface
INITIAL_SIZE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the specified element to this heap.Returns the comparator used by this heap.booleanisEmpty()Returns true if there are no elements in this heap, false otherwise.remove()Removes and returns the element with the highest priority.intsize()Returns the number of elements stored in this heap.
-
Constructor Details
-
Heap
Constructs an empty heap.- Parameters:
comparator- used to determine which of two elements has a higher priority.
-
-
Method Details
-
remove
Description copied from interface:HeapInterfaceRemoves and returns the element with the highest priority.- Specified by:
removein interfaceHeapInterface<E>- Returns:
- element with the highest priority.
-
add
Description copied from interface:HeapInterfaceAdds the specified element to this heap.- Specified by:
addin interfaceHeapInterface<E>- Parameters:
element- the element to add to this heap.
-
size
public int size()Description copied from interface:HeapInterfaceReturns the number of elements stored in this heap.- Specified by:
sizein interfaceHeapInterface<E>- Returns:
- number of elements in this heap.
-
isEmpty
public boolean isEmpty()Description copied from interface:HeapInterfaceReturns true if there are no elements in this heap, false otherwise.- Specified by:
isEmptyin interfaceHeapInterface<E>- Returns:
- true if there are no elements in this heap, false otherwise.
-
comparator
Description copied from interface:HeapInterfaceReturns the comparator used by this heap.- Specified by:
comparatorin interfaceHeapInterface<E>- Returns:
- the comparator used by this heap.
-