T
- object typepublic final class PriorityQ<T>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
(package private) T[] |
a |
(package private) java.util.Comparator<T> |
comp |
(package private) int |
lastIndex |
Constructor and Description |
---|
PriorityQ(int maxSize,
java.util.Comparator<T> c)
Construct a priority queue with a given capacity
|
Modifier and Type | Method and Description |
---|---|
void |
buildHeap()
build the heap...
|
private int |
compare(T a,
T b) |
boolean |
isEmpty()
Check whether the heap is empty.
|
T |
peek()
Look at the top of the heap
|
void |
percolateDown()
Signals that the element on top of the heap has been updated
|
private void |
percolateDown(int i) |
T |
poll()
Remove the element on top of the heap
|
int |
size() |
void |
toss(T t)
Add an element at the end of the queue
|
public PriorityQ(int maxSize, java.util.Comparator<T> c)
maxSize
- capacityc
- comparatorpublic int size()
public void toss(T t)
t
- element to be addedpublic T peek()
public void buildHeap()
public void percolateDown()
private void percolateDown(int i)
public T poll()
public boolean isEmpty()