Package sim.util

Class Heap

java.lang.Object
sim.util.Heap
All Implemented Interfaces:
Serializable

public class Heap extends Object implements 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 Details

  • Method Details

    • getKeys

      public Comparable[] getKeys()
    • getObjects

      public Object[] getObjects()
    • getMinKey

      public Comparable getMinKey()
      Returns the key value of the current min element. Returns null if there is no such element. Does not extract the element.
    • getMin

      public Object getMin()
      Returns the current min element. Returns null if there is no such element. Does not extract the element.
    • extractMin

      public Bag extractMin(Bag putInHere)
      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

      public Object 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

      public void add(Object elem, Comparable key)
      Adds an element to the heap with the given key.
    • size

      public int size()
    • isEmpty

      public boolean isEmpty()
    • clear

      public void clear()
    • merge

      public Heap merge(Heap other)
      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.