|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--org.jwarp.util.BinaryHeap
Iterface for priority queues. This interface does not dictate whether it is min or max heap.
| Field Summary | |
protected static int |
DEFAULT_CAPACITY
The default capacity |
protected java.lang.Comparable[] |
m_elements
The current elements |
protected boolean |
m_isMinHeap
Is the heap a minimal heap |
protected int |
m_size
The current size |
| Constructor Summary | |
BinaryHeap()
Creates a new binary heap. |
|
BinaryHeap(boolean isMinHeap)
Creates a new binary heap telling it to be a minimal heap or not. |
|
BinaryHeap(int capacity)
Creates a new binary heap with the given capacity. |
|
BinaryHeap(int capacity,
boolean isMinHeap)
Creates a new binary heap telling it to be a minimal heap or not and setting its start capacity. |
|
| Method Summary | |
void |
clear()
Clear all elements from queue. |
protected void |
grow()
Grow the heap |
void |
insert(java.lang.Comparable element)
Insert an element into queue. |
boolean |
isEmpty()
Test if queue is empty. |
boolean |
isFull()
Test if queue is full. |
java.lang.Comparable |
peek()
Return element on top of heap but don't remove it. |
protected void |
percolateDownMaxHeap(int index)
Percolate element down heap from top. |
protected void |
percolateDownMinHeap(int index)
Percolate element down heap from top. |
protected void |
percolateUpMaxHeap(java.lang.Comparable element)
Percolate element up heap from bottom. |
protected void |
percolateUpMinHeap(java.lang.Comparable element)
Percolate element up heap from bottom. |
java.lang.Comparable |
pop()
Return element on top of heap and remove it. |
java.lang.String |
toString()
Construct a string represntation. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
protected static final int DEFAULT_CAPACITY
protected int m_size
protected java.lang.Comparable[] m_elements
protected boolean m_isMinHeap
| Constructor Detail |
public BinaryHeap()
public BinaryHeap(int capacity)
capacity - The capacitypublic BinaryHeap(boolean isMinHeap)
isMinHeap - Is the heap minimal or not
public BinaryHeap(int capacity,
boolean isMinHeap)
capacity - The capacityisMinHeap - Is the heap minimal or not| Method Detail |
public void clear()
clear in interface IPriorityQueuepublic boolean isEmpty()
isEmpty in interface IPriorityQueuepublic boolean isFull()
public void insert(java.lang.Comparable element)
insert in interface IPriorityQueueelement - the element to be inserted
public java.lang.Comparable peek()
throws java.util.NoSuchElementException
peek in interface IPriorityQueuejava.util.NoSuchElementException - if isEmpty() == true
public java.lang.Comparable pop()
throws java.util.NoSuchElementException
pop in interface IPriorityQueuejava.util.NoSuchElementException - if isEmpty() == trueprotected void percolateDownMinHeap(int index)
element - the elementprotected void percolateDownMaxHeap(int index)
element - the elementprotected void percolateUpMinHeap(java.lang.Comparable element)
element - the elementprotected void percolateUpMaxHeap(java.lang.Comparable element)
element - the elementprotected void grow()
public java.lang.String toString()
toString in class java.lang.Object
|
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||