|
APCS Java Subset | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectap.ArrayPriorityQueue
A simple yet completely functional implementation
of the PriorityQueue
interface. The interface
is part of the AP subset and is testable. This implementation
is not part of the subset, but is useful in
a classroom setting.
This class supports (n = # items stored in priority queue)
PriorityQueue
operations with the following
complexities.
operation | worst case | average case |
---|---|---|
add | O(1) | O(1) |
peekMin | O(n) | O(n) |
removeMin | O(n) | O(n) |
The underlying storage is java.util.ArrayList
which
supports constant time add (to end), but which requires linear
search to find the smallest element.
This implementation is provided at apcentral.
Constructor Summary | |
ArrayPriorityQueue()
Constructs an initially 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 ArrayPriorityQueue()
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 |