|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure.SkewHeap<ELTTYPE>
public class SkewHeap<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
An implementation of a priority queue using skew heaps. Skew heaps allow one to construct heaps dynamically without explictly balancing the heaps. Main operation is a merge. Most operations execute in amortized logarithmic time, but individual operations may take linear time to execute in the worst case.
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 SkewHeap programmers = newSkewHeap()
; //add programmers and their ages to heap //ages current of 7/22/2002 //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."); } }
Constructor Summary | |
---|---|
SkewHeap()
Constructs an empty priority queue. |
Method Summary | |
---|---|
void |
add(ELTTYPE value)
Add a value to the priority queue. |
void |
clear()
Remove all the elements from the queue. |
ELTTYPE |
getFirst()
Fetch lowest valued (highest priority) item from queue. |
boolean |
isEmpty()
Determine if the queue is empty. |
static void |
main(java.lang.String[] argv)
|
void |
merge(MergeableHeap<ELTTYPE> otherHeap)
Merge this heap with another |
ELTTYPE |
remove()
Returns the minimum value from the queue. |
int |
size()
Determine the size of the queue. |
java.lang.String |
toString()
Construct a string representation of the heap. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SkewHeap()
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 value to be added.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 boolean isEmpty()
isEmpty
in interface PriorityQueue<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
public void merge(MergeableHeap<ELTTYPE> otherHeap)
merge
in interface MergeableHeap<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
otherHeap
- Heap to be merged with this heap, otherHeap
is destroyed by this operation;public java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] argv)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |