|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure.VectorHeap
public class VectorHeap
This class implements a priority queue based on a traditional array-based heap.
Field Summary | |
---|---|
protected Vector |
data
The data, kept in heap order. |
Constructor Summary | |
---|---|
VectorHeap()
Construct a new priority queue |
|
VectorHeap(Vector v)
Construct a new priority queue from an unordered vector |
Method Summary | |
---|---|
void |
add(java.lang.Comparable value)
Add a value to the priority queue. |
void |
clear()
Remove all the elements from the queue. |
java.lang.Comparable |
getFirst()
Fetch lowest valued (highest priority) item from queue. |
boolean |
isEmpty()
Determine if the queue is empty. |
protected static int |
left(int i)
Returns left child index. |
protected static int |
parent(int i)
Returns parent index |
protected void |
percolateUp(int leaf)
Moves node upward to appropriate position within heap. |
protected void |
pushDownRoot(int root)
Moves node downward, into appropriate position within subheap. |
java.lang.Comparable |
remove()
Returns the minimum value from the queue. |
protected static int |
right(int i)
Returns right child index. |
int |
size()
Determine the size of the queue. |
java.lang.String |
toString()
Construct a string representation of the heap. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Vector data
Constructor Detail |
---|
public VectorHeap()
public VectorHeap(Vector v)
Method Detail |
---|
protected static int parent(int i)
i
- a node index
protected static int left(int i)
i
- a node index
protected static int right(int i)
i
- a node index
public java.lang.Comparable getFirst()
getFirst
in interface PriorityQueue
public java.lang.Comparable remove()
remove
in interface PriorityQueue
public void add(java.lang.Comparable value)
add
in interface PriorityQueue
value
- The value to be added.public boolean isEmpty()
isEmpty
in interface PriorityQueue
protected void percolateUp(int leaf)
leaf
- Index of the node in the heap.protected void pushDownRoot(int root)
root
- Index of the root of the subheap.public int size()
size
in interface PriorityQueue
public void clear()
clear
in interface PriorityQueue
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |