Package sim.util
Class Heap
java.lang.Object
sim.util.Heap
- All Implemented Interfaces:
Serializable
Implementations of Heap functions in Java. This code is derived
from the HeapSort example algorithm in Introduction to algorithms by
Cormen, Leiserson and Rivest. Intentionally very simple.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(Object elem, Comparable key) Adds an element to the heap with the given key.void
clear()
Removes the first minimum element and its key from the heap, and returns the minimum element.extractMin
(Bag putInHere) Removes all key-equal minimum elements and adds them to a Bag, which is then is returned.getKeys()
getMin()
Returns the current min element.Returns the key value of the current min element.Object[]
boolean
isEmpty()
Produces a new heap which is the union of this heap with the other.int
size()
-
Constructor Details
-
Heap
public Heap() -
Heap
-
-
Method Details
-
getKeys
-
getObjects
-
getMinKey
Returns the key value of the current min element. Returns null if there is no such element. Does not extract the element. -
getMin
Returns the current min element. Returns null if there is no such element. Does not extract the element. -
extractMin
Removes all key-equal minimum elements and adds them to a Bag, which is then is returned. You may provide a Bag -- putInHere -- to be filled in. -
extractMin
Removes the first minimum element and its key from the heap, and returns the minimum element. Will return null if the heap is empty -
add
Adds an element to the heap with the given key. -
size
public int size() -
isEmpty
public boolean isEmpty() -
clear
public void clear() -
merge
Produces a new heap which is the union of this heap with the other. The original heaps are not modified. The new heap is returned.
-