Package edu.uky.ai.util
Class MinPriorityQueue<T>
java.lang.Object
edu.uky.ai.util.MinPriorityQueue<T>
- Type Parameters:
T
- the type of object this queue will hold
A min priority queue which, instead of using a
Comparator
, allows
the user to specify a numeric key that should be associated with the item
being added to the queue. When an item is popped off this queue, it will
always be the item with the lowest key. This queue may hold multiple copies
of the same object with different keys. This class relies on
PriorityQueue
.- Author:
- Stephen G. Ware
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
isEmpty()
Tests whether this queue is empty.peek()
Returns, but does not remove, the object with the lowest key value (i.e.pop()
Removes and returns to the object with the lowest key.void
Associates an object with a given key and adds it to the queue.int
size()
Returns the number of objects currently stored in this queue.
-
Constructor Details
-
MinPriorityQueue
public MinPriorityQueue()Constructs a new, empty min priority queue.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Tests whether this queue is empty.- Returns:
- true if it is empty, false otherwise
-
size
public int size()Returns the number of objects currently stored in this queue.- Returns:
- the size
-
peek
Returns, but does not remove, the object with the lowest key value (i.e. the next object to be removed).- Returns:
- the object
-
push
Associates an object with a given key and adds it to the queue.- Parameters:
element
- the object to addpriority
- the key to associate with the object
-
pop
Removes and returns to the object with the lowest key.- Returns:
- the object
-