Class AbstractArrayHeap<K>

java.lang.Object
org.jheaps.array.AbstractArrayWeakHeap<K>
org.jheaps.array.AbstractArrayHeap<K>
Type Parameters:
K - the type of keys maintained by this heap
All Implemented Interfaces:
Serializable, Heap<K>
Direct Known Subclasses:
BinaryArrayHeap, DaryArrayHeap, MinMaxBinaryArrayDoubleEndedHeap

abstract class AbstractArrayHeap<K> extends AbstractArrayWeakHeap<K>
Abstract implementation of a heap using an array representation.
  • Field Details

  • Constructor Details

    • AbstractArrayHeap

      public AbstractArrayHeap(Comparator<? super K> comparator, int capacity)
      Construct a new heap
      Parameters:
      comparator - the comparator to use
      capacity - the initial capacity
  • Method Details

    • initCapacity

      protected void initCapacity(int capacity)
      Initialize the array representation
      Specified by:
      initCapacity in class AbstractArrayWeakHeap<K>
      Parameters:
      capacity - the capacity
    • findMin

      public K findMin()
      Find an element with the minimum key.
      Returns:
      an element with the minimum key
    • insert

      public void insert(K key)
      Insert a key into the heap.
      Parameters:
      key - the key to insert
    • deleteMin

      public K deleteMin()
      Delete and return an element with the minimum key. If multiple such elements exists, only one of them will be deleted.
      Returns:
      the deleted element with the minimum key