Package com.zybooks.dsaj.pq
Class SortedPriorityQueue<K,V>
java.lang.Object
com.zybooks.dsaj.pq.AbstractPriorityQueue<K,V>
com.zybooks.dsaj.pq.SortedPriorityQueue<K,V>
- Type Parameters:
K
- The key type (keys must be unique and comparable)V
- The value type stored with each entry
- All Implemented Interfaces:
PriorityQueue<K,
V>
An implementation of a priority queue with a sorted list.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.zybooks.dsaj.pq.AbstractPriorityQueue
AbstractPriorityQueue.PQEntry<K,
V> -
Constructor Summary
ConstructorDescriptionCreates an empty priority queue based on the natural ordering of its keys.SortedPriorityQueue
(Comparator<K> comp) Creates an empty priority queue using the given comparator to order keys. -
Method Summary
Methods inherited from class com.zybooks.dsaj.pq.AbstractPriorityQueue
compare, createEntry, isEmpty
-
Constructor Details
-
SortedPriorityQueue
public SortedPriorityQueue()Creates an empty priority queue based on the natural ordering of its keys. -
SortedPriorityQueue
Creates an empty priority queue using the given comparator to order keys.- Parameters:
comp
- comparator defining the order of keys in the priority queue
-
-
Method Details
-
insert
Inserts a key-value pair and returns the entry created.- Parameters:
key
- the key of the new entryvalue
- the associated value of the new entry- Returns:
- the entry storing the new key-value pair
-
min
Returns (but does not remove) an entry with minimal key.- Returns:
- entry having a minimal key (or null if empty)
-
removeMin
Removes and returns an entry with minimal key.- Returns:
- the removed entry (or null if empty)
-
size
public int size()Returns the number of items in the priority queue.- Returns:
- number of items
-