|
APCS Java Subset | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectap.HeapPriorityQueue
This class implements the PriorityQueue interface using a binary heap. For algorithmic and data structure details see Mark Weiss' Data Structures and Problem Solving with Java, Addison Wesley.
This class supports (n = # items stored in priority queue)
operation | worst case | average case |
---|---|---|
add | O(log n) | O(1) |
peekMin | O(1) | O(1) |
removeMin | O(log n) | O(log n) |
Implementation concepts borrowed from Mark Weiss; the basic idea is that the node whose index is k has children stored with indexes 2*k and 2*k+1 for left/right children, respectively. The root of the binary heap has index 1.
Constructor Summary | |
HeapPriorityQueue()
Constructs an empty priority queue. |
Method Summary | |
void |
add(java.lang.Object x)
Adds an item to this priority queue. |
boolean |
isEmpty()
Returns true if this stack is empty, otherwise returns false. |
java.lang.Object |
peekMin()
Returns the smallest item stored in this priority queue without removing it. |
java.lang.Object |
removeMin()
Removes and returns the smallest item stored in this priority queue. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public HeapPriorityQueue()
Method Detail |
public void add(java.lang.Object x)
PriorityQueue
add
in interface PriorityQueue
x
- is the object added to this priority queuepublic java.lang.Object removeMin()
PriorityQueue
removeMin
in interface PriorityQueue
public java.lang.Object peekMin()
PriorityQueue
peekMin
in interface PriorityQueue
public boolean isEmpty()
PriorityQueue
isEmpty
in interface PriorityQueue
|
unofficial documentation for the APCS Java Subset | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |