|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimple.util.PriorityQueue
public class PriorityQueue
This class implements a PriorityQueue
. This class
is implemented in such a way that objects are added using an
add
function. The add
function takes
two paramaters an object and a long.
The object represents an item in the queue, the long indicates its priority in the queue. The remove function in this class returns the object first in the queue and that object is removed from the queue permentaly.
Field Summary | |
---|---|
protected int |
capacity
This holds the number elements this queue can have. |
protected int |
count
Holds the number of elements currently in the queue. |
protected java.lang.Object[] |
data
This contains the list of objects in the queue. |
protected long |
maxPriority
The maximum priority possible in this priority queue. |
protected long[] |
value
This contains the list of prioritys in the queue. |
Constructor Summary | |
---|---|
PriorityQueue()
Creates a new PriorityQueue object. |
|
PriorityQueue(int capacity)
Creates a new PriorityQueue object. |
|
PriorityQueue(int capacity,
long maxPriority)
Creates a new PriorityQueue object. |
Method Summary | |
---|---|
void |
add(java.lang.Object element,
long priority)
This function adds the given object into the PriorityQueue ,
its priority is the long priority. |
protected void |
bubbleDown(int pos)
Bubble down is used to put the element at subscript 'pos' into it's rightfull place in the heap (a heap is another name used for PriorityQueue ). |
protected void |
bubbleUp(int pos)
Bubble up is used to place an element relatively low in the queue to it's rightful place higher in the queue, but only if it's priority allows it to do so, similar to bubbleDown only in the other directon this swaps out its parents. |
void |
clear()
This method will empty the queue. |
protected void |
expandCapacity()
This ensures that there is enough space to keep adding elements to the priority queue. |
int |
length()
The number of elements in the queue. |
java.lang.Object |
remove()
Remove is a function to remove the element in the queue with the maximum priority. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected long maxPriority
protected java.lang.Object[] data
protected long[] value
protected int count
protected int capacity
Constructor Detail |
---|
public PriorityQueue()
PriorityQueue
object. The
PriorityQueue
object allows objects to be
entered into the queue and to leave in the order of
priority, the highest priority get's to leave first.
public PriorityQueue(int capacity)
PriorityQueue
object. The
PriorityQueue
object allows objects to
be entered into the queue an to leave in the order of
priority, the highest priority get's to leave first.
capacity
- the initial capacity of the queue before
a resizepublic PriorityQueue(int capacity, long maxPriority)
PriorityQueue
object. The
PriorityQueue
object allows objects to
be entered into the queue an to leave in the order of
priority, the highest priority get's to leave first.
capacity
- the initial capacity of the queue before
a resizemaxPriority
- is the maximum possible priority for
an objectMethod Detail |
---|
public void add(java.lang.Object element, long priority)
PriorityQueue
,
its priority is the long priority. The way in which priority can be
associated with the elements of the queue is by keeping the priority
and the elements array entrys parallel.
element
- is the object that is to be entered into this
PriorityQueue
priority
- this is the priority that the object holds in the
PriorityQueue
public java.lang.Object remove()
protected void bubbleDown(int pos)
PriorityQueue
). If the priority of an element
at subscript 'pos' is less than it's children then it must
be put under one of these children, that is, the ones with the
maximum priority must come first.
pos
- the position the bubble down procedure starts fromprotected void bubbleUp(int pos)
pos
- the position the bubble up procedure starts fromprotected void expandCapacity()
public void clear()
public int length()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |