|
Algorithm Development Kit 1.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectalgs.model.heap.BinaryHeap<E>
E
- Type of entity to insert into Heap, which must provide Comparablepublic class BinaryHeap<E extends java.lang.Comparable<E>>
A Binary Heap that can be used as a Priority Queue since it enables elements to have its priority updated while in queue.
The elements in the queue have an integer ID and given PRIORITY.
Constructor Summary | |
---|---|
BinaryHeap(int n)
Construct Binary Heap of the given size. |
Method Summary | |
---|---|
void |
decreaseKey(int id,
java.lang.Comparable<E> reducedPriority)
Decrease the priority of the known element in the Binary Heap with the given identifier. |
void |
insert(int id,
java.lang.Comparable<E> priority)
Insert the element (id) with given priority. |
boolean |
isEmpty()
Determines if Binary Heap is empty. |
java.lang.Comparable<E> |
smallest()
Return the PRIORITY of the smallest entry. |
int |
smallestID()
Return the integer IDENTIFIER of the smallest entry. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BinaryHeap(int n)
Since we cannot parameterize Element[] construction, this method suppresses warnings.
n
- size of array.Method Detail |
---|
public boolean isEmpty()
public java.lang.Comparable<E> smallest()
public int smallestID()
public void insert(int id, java.lang.Comparable<E> priority)
Inserting too many items into a Binary Heap will cause exception.
id
- priority
- public void decreaseKey(int id, java.lang.Comparable<E> reducedPriority)
No check is done to see if the new "reducedPriority" is in fact actually less than the actual priority of the element in the Binary Heap. Be careful that you only call with proper smaller element.
id
- reducedPriority
-
|
Algorithm Development Kit 1.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |