|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectm865.datastructures.AbstractPriorityQueue
m865.datastructures.PriorityQueueAL
public class PriorityQueueAL
This class implements a Queue using a dynamic array Version 2.1 incorporated a new class roster. Version 3.0 eliminated Cloneable to bring it in line with the java.util conventions. Version 3.0 also simplified the iterator so that it simply dumps the queue in the array order.
Nested Class Summary | |
---|---|
class |
PriorityQueueAL.PriorityQueueALIterator
The iterator for this PriorityQueueAL class. |
Field Summary | |
---|---|
protected java.util.ArrayList<Prioritizeable> |
pq
The dynamic array is implemented with the java.util.ArrayList |
Fields inherited from class m865.datastructures.AbstractPriorityQueue |
---|
hash |
Constructor Summary | |
---|---|
PriorityQueueAL()
Constructs a queue whose dynamic array has the default initial size for a ArrayList. |
|
PriorityQueueAL(java.util.Collection c)
Constructs a priority queue which is initialized with the objects in the specified collection. |
|
PriorityQueueAL(int capacity)
Constructs a priority queue whose dynamic array has a specified initial size. |
Method Summary | |
---|---|
void |
adjustPriority(Prioritizeable obj,
java.lang.Comparable priority)
Locates the specified object in the heap, changes its priority to the specified priority, and adjusts the location of the object in the heap. |
protected void |
bubbleUp(int child)
Moves this item at the specified position up the heap according to its priority. |
void |
clear()
Removes all the objects from this queue. |
boolean |
contains(java.lang.Object obj)
Determines whether the specified object is contained in the priority queue. |
Prioritizeable |
dequeue()
Removes and returns the object at the beginning of the queue. |
void |
enqueue(Prioritizeable pqi)
Appends an object to the end of the queue. |
boolean |
equals(java.lang.Object obj)
The test for equality. |
java.util.Iterator |
iterator()
A factory method which returns an Iterator to the collection in this priority queue. |
static void |
main(java.lang.String[] args)
This main method tests the PriorityQueueAL class to insure that the elementary functions are correct. |
Prioritizeable |
peek()
Returns the object at the beginning of the queue. |
boolean |
remove(java.lang.Object obj)
Removes the specified object from this priority queue. |
protected void |
siftDown(int parent)
Moves this item at the specified position down the heap according to its priority. |
int |
size()
Determines the size of this prioirity queue. |
java.lang.String |
toString()
List the objects in the priority queue in their priorty order. |
Methods inherited from class m865.datastructures.AbstractPriorityQueue |
---|
add, addAll, containsAll, downdateHashCode, hashCode, isEmpty, removeAll, retainAll, toArray, toArray, updateHashCode |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.ArrayList<Prioritizeable> pq
Constructor Detail |
---|
public PriorityQueueAL(int capacity)
capacity
- the initial size of the dynamic array.public PriorityQueueAL()
public PriorityQueueAL(java.util.Collection c)
c
- the collection of objects to be initially added to this
priority queue.Method Detail |
---|
protected void bubbleUp(int child)
child
- the index of the specified itempublic void enqueue(Prioritizeable pqi)
enqueue
in class AbstractPriorityQueue
pqi
- the object to be appended to the end of the queue.protected void siftDown(int parent)
parent
- the index of the specified itempublic Prioritizeable dequeue()
dequeue
in class AbstractPriorityQueue
public Prioritizeable peek()
peek
in class AbstractPriorityQueue
public void adjustPriority(Prioritizeable obj, java.lang.Comparable priority)
adjustPriority
in class AbstractPriorityQueue
obj
- the specified prioritizeable objectpriority
- the specified new prioritypublic void clear()
public boolean contains(java.lang.Object obj)
contains
in interface java.util.Collection
contains
in class AbstractPriorityQueue
obj
- the specified object to be located in the heap.
public boolean equals(java.lang.Object obj)
equals
in interface java.util.Collection
equals
in class AbstractPriorityQueue
obj
- the object which may be equal to this queue.
public java.util.Iterator iterator()
public boolean remove(java.lang.Object obj)
obj
- the specified object to be removed
public int size()
public java.lang.String toString()
toString
in class AbstractPriorityQueue
public static void main(java.lang.String[] args)
args
- optional command line argument that will be ignored.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |