T
- type of item on the heappublic class Heap<T> extends Object
This class is not thread-safe.
Unlike the PriorityQueue
, this class allows external
entities to force re-establishment of the heap property via heapify
method as a response to any mutations in elements' relative priorities.
Constructor and Description |
---|
Heap(T[] data,
int size,
Comparator<T> comparator)
Creates a new heap using the supplied array of items as the heap
backing.
|
Modifier and Type | Method and Description |
---|---|
T |
extractExtreme()
Extracts the item that represents the heap extreme.
|
T |
extreme()
Returns the item that represents the heap extreme.
|
void |
heapify()
Rearranges the backing array of items to establish the heap property.
|
Heap<T> |
insert(T item)
Inserts a new item into the heap.
|
boolean |
isEmpty()
Indicates whether the heap contains any items or not.
|
Iterator<T> |
iterator()
Returns non-destructive level-by-level top-down heap iterator.
|
int |
size()
Returns the heap size, i.e.
|
public Heap(T[] data, int size, Comparator<T> comparator)
data
- array to be used as heap backingsize
- initial size of heapcomparator
- comparator to be used for comparing itemspublic void heapify()
This should be called following any change of the item key value.
public int size()
public boolean isEmpty()
public T extreme()
public T extractExtreme()
public Heap<T> insert(T item)
item
- item to be insertedIllegalStateException
- if the heap is fullCopyright © 2015. All Rights Reserved.