|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure.PriorityVector<ELTTYPE>
public class PriorityVector<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
A vector-based implementation of a priority queue. Similar to an ordered vector, except that only the smallest value may be accessed in this structure.
Example usage:
To print out a list of programmers sorted by age we could use the following:
public static void main(String[] argv){ //initialize a new fib heap PriorityVector programmers = newPriorityVector()
; //add programmers and their ages to heap //ages current of 7/22/2002 programmers.add(new ComparableAssociation(new Integer(22), "Evan"))
; programmers.add(new ComparableAssociation(new Integer(19), "Chris")); programmers.add(new ComparableAssociation(new Integer(20), "Shimon")); programmers.add(new ComparableAssociation(new Integer(21), "Diane")); programmers.add(new ComparableAssociation(new Integer(21), "Lida")); programmers.add(new ComparableAssociation(new Integer(20), "Rob")); programmers.add(new ComparableAssociation(new Integer(20), "Sean")); //print out programmers while(!programmers.isEmpty()
){ ComparableAssociation p = (ComparableAssociation)programmers.remove()
; System.out.println(p.getValue() + " is " + p.getKey() + " years old."); } }
OrderedVector
Constructor Summary | |
---|---|
PriorityVector()
Construct an empty priority queue. |
Method Summary | |
---|---|
void |
add(ELTTYPE value)
Add a comparable value to the priority queue. |
void |
clear()
Remove all the values from the priority queue. |
ELTTYPE |
getFirst()
Fetch the smallest value of the priority queue. |
boolean |
isEmpty()
Determine if the priority queue is empty. |
ELTTYPE |
remove()
Remove the smallest value of the structure. |
int |
size()
Determine the size of the priority queue. |
java.lang.String |
toString()
Construct a string representation of the priority vector. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public PriorityVector()
Method Detail |
---|
public ELTTYPE getFirst()
getFirst
in interface PriorityQueue<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
public ELTTYPE remove()
remove
in interface PriorityQueue<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
public void add(ELTTYPE value)
add
in interface PriorityQueue<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
value
- The comparable value to be added.public boolean isEmpty()
isEmpty
in interface PriorityQueue<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
public int size()
size
in interface PriorityQueue<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
public void clear()
clear
in interface PriorityQueue<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |