public class PriorityQueue
extends java.lang.Object
Comparable
objects.Modifier and Type | Field and Description |
---|---|
private java.util.ArrayList |
items |
private int |
size |
Constructor and Description |
---|
PriorityQueue()
Creates a new empty priority queue
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.Comparable x)
Insert into the priority queue.
|
void |
clear()
Make the priority queue logically empty.
|
boolean |
isEmpty()
Test if the priority queue is logically empty.
|
java.lang.Object |
poll()
Remove the smallest item from the priority queue.
|
private void |
reorder(int hole)
Internal method to percolate down in the heap.
|
int |
size()
Returns size.
|
public void add(java.lang.Comparable x)
x
- the item to insert.public boolean isEmpty()
public int size()
public void clear()
public java.lang.Object poll()
private void reorder(int hole)
hole
- the index at which the percolate begins.