Class Heap<E>

Type Parameters:
E - Type of elements stored in this heap
All Implemented Interfaces:
HeapInterface<E>

public class Heap<E> extends Object implements HeapInterface<E>
A generic heap that stores elements in a a generic array.
  • Constructor Details

    • Heap

      public Heap(Comparator<E> comparator)
      Constructs an empty heap.
      Parameters:
      comparator - used to determine which of two elements has a higher priority.
  • Method Details

    • remove

      public E remove()
      Description copied from interface: HeapInterface
      Removes and returns the element with the highest priority.
      Specified by:
      remove in interface HeapInterface<E>
      Returns:
      element with the highest priority.
    • add

      public void add(E element)
      Description copied from interface: HeapInterface
      Adds the specified element to this heap.
      Specified by:
      add in interface HeapInterface<E>
      Parameters:
      element - the element to add to this heap.
    • size

      public int size()
      Description copied from interface: HeapInterface
      Returns the number of elements stored in this heap.
      Specified by:
      size in interface HeapInterface<E>
      Returns:
      number of elements in this heap.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: HeapInterface
      Returns true if there are no elements in this heap, false otherwise.
      Specified by:
      isEmpty in interface HeapInterface<E>
      Returns:
      true if there are no elements in this heap, false otherwise.
    • comparator

      public Comparator<E> comparator()
      Description copied from interface: HeapInterface
      Returns the comparator used by this heap.
      Specified by:
      comparator in interface HeapInterface<E>
      Returns:
      the comparator used by this heap.