T
- the type of data the queue stores.
public class MysteryPriorityQueueImplementation<T extends java.lang.Comparable<? super T>> extends java.lang.Object implements PriorityQueue<T>
Note that the relative priority of elements is defined by the compareTo() method defined for the type of items stored in the queue. In other words, the priority of an item is equal to the value of the item.
See also PriorityPair and DefaultPriorityPairImplementation for the tools that let you separate the priority of each entry from its value.
Note that this interface defines a *max* priority queue; the item with the highest priority is what comes out of the queue. The easiest way to get a *min* priority queue is to separate priorities and values, and negate the priorities that you use.
Constructor and Description |
---|
MysteryPriorityQueueImplementation()
Constructs an empty priority queue.
|
Modifier and Type | Method and Description |
---|---|
void |
add(T entry)
Adds an item to the queue.
|
void |
clear()
Removes all items from the queue.
|
boolean |
isEmpty()
Returns true if the queue is empty.
|
T |
peek()
Returns the maximum item in the queue, without removing it.
|
T |
remove()
Removes the maximum item from the queue, and returns it.
|
public MysteryPriorityQueueImplementation()
public void add(T entry)
PriorityQueue
add
in interface PriorityQueue<T extends java.lang.Comparable<? super T>>
public T remove()
PriorityQueue
remove
in interface PriorityQueue<T extends java.lang.Comparable<? super T>>
public T peek()
PriorityQueue
peek
in interface PriorityQueue<T extends java.lang.Comparable<? super T>>
public boolean isEmpty()
PriorityQueue
isEmpty
in interface PriorityQueue<T extends java.lang.Comparable<? super T>>
public void clear()
PriorityQueue
clear
in interface PriorityQueue<T extends java.lang.Comparable<? super T>>