|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectheap.MyHeap<K,V>
public class MyHeap<K,V>
An implementation of an adaptable priority queue by means of a heap. Be certain that your running times match those specified in the program documentation, and remember that the running time of a "called" method sets the minimum running time of the "calling" method. Feel free to add additional comments.
| Constructor Summary | |
|---|---|
MyHeap(Comparator<K> comparator)
Creates an empty heap with the given comparator. |
|
| Method Summary | |
|---|---|
CompleteBinaryTree<Entry<K,V>> |
getTree()
Returns a CompleteBinaryTree that will allow the visualizer access to private members, shattering encapsulation, but allowing visualization of the heap. |
Entry<K,V> |
insert(K key,
V value)
Inserts a key-value pair and returns the entry created. |
boolean |
isEmpty()
Returns whether the heap is empty. |
Entry<K,V> |
min()
Returns but does not remove an entry with minimum key. |
Entry<K,V> |
remove(Entry<K,V> entry)
Removes and returns the given entry from the heap. |
Entry<K,V> |
removeMin()
Removes and returns an entry with minimum key. |
K |
replaceKey(Entry<K,V> entry,
K key)
Replaces the key of the given entry. |
V |
replaceValue(Entry<K,V> entry,
V value)
Replaces the value of the given entry. |
void |
setComparator(Comparator<K> comparator)
Sets the comparator used for comparing items in the heap. |
int |
size()
Returns the size of the heap. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MyHeap(Comparator<K> comparator)
comparator - the comparator to be used for heap keys| Method Detail |
|---|
public void setComparator(Comparator<K> comparator)
throws IllegalStateException
comparator - the comparator to be used for heap keys
IllegalStateException - if priority queue is not emptypublic CompleteBinaryTree<Entry<K,V>> getTree()
getTree in interface HeapWrapper<K,V>public 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 - if the heap is empty
public Entry<K,V> insert(K key,
V value)
throws InvalidKeyException
insert in interface PriorityQueue<K,V>key - to be used as the key the heap is sorting withvalue - stored with the associated key in the heap
InvalidKeyException - if the key is not suitable for this heap
public Entry<K,V> removeMin()
throws EmptyPriorityQueueException
removeMin in interface PriorityQueue<K,V>EmptyPriorityQueueException - if the heap is empty
public Entry<K,V> remove(Entry<K,V> entry)
throws InvalidEntryException
remove in interface AdaptablePriorityQueue<K,V>entry - to be removed from the heap
InvalidEntryException - if the entry cannot be removed from this heap
public K replaceKey(Entry<K,V> entry,
K key)
throws InvalidEntryException
replaceKey in interface AdaptablePriorityQueue<K,V>entry - within which the key will be replacedkey - to replace the existing key in the entry
InvalidEntryException - if the entry cannot have its key replaced
public V replaceValue(Entry<K,V> entry,
V value)
throws InvalidEntryException
replaceValue in interface AdaptablePriorityQueue<K,V>entry - within which the value will be replacedvalue - to replace the existing value in the entry
InvalidEntryException - if the entry cannot have its value replaced
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||