public class SortedListPriorityQueue<K,V> extends java.lang.Object implements PriorityQueue<K,V>
Modifier and Type | Class and Description |
---|---|
protected static class |
SortedListPriorityQueue.MyEntry<K,V>
Inner class for entries
|
Modifier and Type | Field and Description |
---|---|
protected Position<Entry<K,V>> |
actionPos |
protected java.util.Comparator<K> |
c |
protected PositionList<Entry<K,V>> |
entries |
Constructor and Description |
---|
SortedListPriorityQueue()
Creates the priority queue with the default comparator.
|
SortedListPriorityQueue(java.util.Comparator<K> comp)
Creates the priority queue with the given comparator.
|
SortedListPriorityQueue(PositionList<Entry<K,V>> list,
java.util.Comparator<K> comp)
Creates the priority queue with the given comparator and list.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkKey(K key)
Determines whether a key is valid.
|
Entry<K,V> |
insert(K k,
V v)
Inserts a key-value pair and return the entry created.
|
protected void |
insertEntry(Entry<K,V> e)
Auxiliary method used for insertion.
|
boolean |
isEmpty()
Returns whether the priority queue is empty.
|
Entry<K,V> |
min()
Returns but does not remove an entry with minimum key.
|
Entry<K,V> |
removeMin()
Removes and returns an entry with minimum key.
|
void |
setComparator(java.util.Comparator<K> comp)
Sets the comparator for this priority queue.
|
int |
size()
Returns the number of elements in the priority queue.
|
java.lang.String |
toString() |
protected PositionList<Entry<K,V>> entries
protected java.util.Comparator<K> c
public SortedListPriorityQueue()
public SortedListPriorityQueue(java.util.Comparator<K> comp)
public SortedListPriorityQueue(PositionList<Entry<K,V>> list, java.util.Comparator<K> comp)
public void setComparator(java.util.Comparator<K> comp) throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if priority queue is not emptypublic int size()
size
in interface PriorityQueue<K,V>
public boolean isEmpty()
isEmpty
in interface PriorityQueue<K,V>
public Entry<K,V> min() throws EmptyPriorityQueueException
min
in interface PriorityQueue<K,V>
EmptyPriorityQueueException
public Entry<K,V> insert(K k, V v) throws InvalidKeyException
insert
in interface PriorityQueue<K,V>
InvalidKeyException
public Entry<K,V> removeMin() throws EmptyPriorityQueueException
removeMin
in interface PriorityQueue<K,V>
EmptyPriorityQueueException
protected boolean checkKey(K key) throws InvalidKeyException
InvalidKeyException
public java.lang.String toString()
toString
in class java.lang.Object