|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectDynamicHeap
Generic heap that also supports FIFO access, backed by a dynamic array; stores items of type Object with priorities of type Comparable, and correctly handles multiple items with the same priority.
Constructor Summary | |
DynamicHeap()
Initializes this heap to be empty. |
Method Summary | |
void |
decreasePriority(java.lang.Object item,
java.lang.Comparable priority)
Decreases the priority of the given item to the given priority value if the new priority is less than the old, does nothing otherwise. |
java.lang.Object |
deleteMinPriority()
Removes the first item with smallest priority from this queue, and returns this item. |
java.lang.Object |
dequeueFIFO()
Removes the item that was inserted first into this queue, and returns this item. |
java.lang.Object |
getMinPriority()
Returns the first item with smallest priority value in this queue. |
int |
getSize()
Returns the current size (number of items) in this queue. |
java.lang.Object |
headFIFO()
Returns the item that was inserted first into this queue. |
void |
insert(java.lang.Object item,
java.lang.Comparable priority)
Adds the given item with the given priority to this queue. |
boolean |
isEmpty()
Returns true if the queue is empty and false otherwise. |
java.lang.String |
toString()
Returns a String representation of this heap. |
java.lang.String |
toStringDebug()
Returns a String representation of this queue that tries to include all information, for debugging. |
java.lang.String |
toStringFIFO()
Returns a String representation of this FIFO queue. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public DynamicHeap()
Method Detail |
public java.lang.String toString()
public java.lang.String toStringFIFO()
public java.lang.String toStringDebug()
public boolean isEmpty()
PriorityQueue
isEmpty
in interface PriorityQueue
public java.lang.Object getMinPriority()
getMinPriority
in interface PriorityQueue
java.lang.NullPointerException
- if this queue is emptyPriorityQueue.getMinPriority()
public java.lang.Object deleteMinPriority()
deleteMinPriority
in interface PriorityQueue
java.lang.NullPointerException
- if this queue is emptyPriorityQueue.deleteMinPriority()
public void insert(java.lang.Object item, java.lang.Comparable priority)
insert
in interface PriorityQueue
item
- the item to add to this queuepriority
- the priority for item
java.lang.NullPointerException
- if item == null or priority == nullPriorityQueue.insert()
public void decreasePriority(java.lang.Object item, java.lang.Comparable priority)
decreasePriority
in interface PriorityQueue
item
- whose priority will be decreasedpriority
- the new priority value for item
java.lang.NullPointerException
- if item == null or priority == nullpublic java.lang.Object headFIFO()
headFIFO
in interface FIFOQueue
java.lang.IndexOutOfBoundsException
- if this queue is emptyFIFOQueue.headFIFO()
public java.lang.Object dequeueFIFO()
dequeueFIFO
in interface FIFOQueue
java.lang.IndexOutOfBoundsException
- if this queue is emptyFIFOQueue.dequeueFIFO()
public int getSize()
getSize
in interface FIFOQueue
FIFOQueue.getSize()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |