|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectPriorityQueue
IntPriorityQueue
public class IntPriorityQueue
A priority queue implemented with a heap where elements are ints in [0,N-1] for some N, where keys are doubles, where lower keys are higher priority, and where the queue may not contain duplicate items. The size of the queue is linear in N, so N should not be outrageous.
Constructor Summary | |
---|---|
IntPriorityQueue(int N)
Initializes an empty priority queue. |
|
IntPriorityQueue(int N,
int[] elems,
double[] keys)
Initializes the priority queue with the given elements. |
Method Summary | |
---|---|
void |
add(int e,
double k)
Inserts the given element into the queue. |
void |
clear()
Resets the priority queue. |
void |
clear(int[] elems,
double[] keys)
Clears the priority queue and then adds the given elements. |
boolean |
contains(int e)
Returns whether the queue contains the given element. |
int |
highest()
Returns the highest priority element. |
double |
highestKey()
Returns the highest priority key. |
void |
incrementKey(int e,
double delta)
Changes the key of the given element by the given value. |
int |
nthElement(int n)
Returns the nth element in the priority queue, where n indicates how the elements are stored not their priority. |
double |
nthKey(int n)
Returns the nth key in the priority queue, where n indicates how the elements are stored not their priority. |
int |
remove()
Removes and returns the highest priority element. |
void |
setKey(int e,
double k)
Sets the key of the given element to the given value. |
int |
size()
Returns the number of elements in the queue. |
String |
toString()
|
Methods inherited from class PriorityQueue |
---|
validateHeapProperty |
Methods inherited from class Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public IntPriorityQueue(int N, int[] elems, double[] keys) throws Exception
N
- defines the elements that may be entered into the queue.elems
- the given elements.keys
- the given elements' keys.
Exception
public IntPriorityQueue(int N)
N
- defines the elements that may be entered into the queue.Method Detail |
---|
public int size()
PriorityQueue
size
in class PriorityQueue
PriorityQueue
public void clear()
PriorityQueue
clear
in class PriorityQueue
PriorityQueue
public void clear(int[] elems, double[] keys) throws Exception
elems
- the given elements.keys
- the given elements' keys.
Exception
public void add(int e, double k) throws Exception
e
- the given element.k
- the given element's key.
Exception
public int highest()
public double highestKey()
public boolean contains(int e)
e
- the given element.
public void setKey(int e, double k) throws Exception
e
- the given element.k
- the given key.
Exception
public void incrementKey(int e, double delta) throws Exception
e
- the given element.delta
- the given value.
Exception
public int remove()
public int nthElement(int n)
n
- identifies the element.
public double nthKey(int n)
n
- identifies the element.
public String toString()
toString
in class Object
Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |