|
© 1998-2002 McGraw-Hill | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
Interface describing mergeable min heaps.
Min heaps are collections of Comparable data that guarantee
efficient access to the smallest element in the structure.
Mergeable Min heaps, also provide an efficient technique for
merging two mergeable heaps of the same type.
Mergeable heaps are quite similar to PriorityQueue.
Example Usage:
public static void main(String[] argv){
//initialize a new fib heap
MergeableHeap programmers = new FibHeap();
//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.PriorityQueue.isEmpty()){
ComparableAssociation p = (ComparableAssociation)programmers.remove();
System.out.println(p.getValue() + " is " + p.getKey() + " years old.");
}
}
| Method Summary | |
void |
add(Comparable value)
Add an item to this heap. |
Comparable |
getFirst()
Return the minimum value in the heap. |
void |
merge(MergeableHeap otherHeap)
Merge this heap with otherHeap, destroying
otherHeap in the process. |
Comparable |
remove()
Returns the minimum value in the heap and deletes this value from the heap. |
| Methods inherited from interface structure.PriorityQueue |
clear, isEmpty, size |
| Method Detail |
public void merge(MergeableHeap otherHeap)
otherHeap, destroying
otherHeap in the process.otherHeap - Heap to be merged into this heap.otherHeap. otherHeap is destroyed in
in the process.public void add(Comparable value)
add in interface PriorityQueuevalue - The value to be added to the heappublic Comparable remove()
remove in interface PriorityQueuepublic Comparable getFirst()
getFirst in interface PriorityQueue
|
© 1998-2002 McGraw-Hill | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||