Interface Heap<E>

  • All Known Implementing Classes:
    ListHeap, TreeHeap

    public interface Heap<E>
    Interface for interacting with a Heap data structure. This implementation extract objects from smallest to largest based on either their natural ordering or the comparator provided to an implementation. While this is a typical of a heap it allows this objects natural ordering to match that of other sorted collections.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void add​(E o)
      Adds the specified object to the heap.
      void clear()
      Clears the contents of the heap.
      E extract()
      Removes the smallest element from the heap and returns it.
      E first()
      Returns the smallest element of the heap.
      boolean isEmpty()
      Returns whether the heap is empty.
      java.util.Iterator<E> iterator()
      Returns an iterator over the elements of the heap.
      E last()
      Returns the largest element of the heap.
      int size()
      Returns the size of the heap.
    • Method Detail

      • extract

        E extract()
        Removes the smallest element from the heap and returns it.
        Returns:
        The smallest element from the heap.
      • first

        E first()
        Returns the smallest element of the heap.
        Returns:
        The top element of the heap.
      • last

        E last()
        Returns the largest element of the heap.
        Returns:
        The largest element of the heap.
      • add

        void add​(E o)
        Adds the specified object to the heap.
        Parameters:
        o - The object to add to the heap.
      • size

        int size()
        Returns the size of the heap.
        Returns:
        The size of the heap.
      • isEmpty

        boolean isEmpty()
        Returns whether the heap is empty.
        Returns:
        true if the heap is empty; false otherwise.
      • iterator

        java.util.Iterator<E> iterator()
        Returns an iterator over the elements of the heap. No specific ordering of these elements is guaranteed.
        Returns:
        An iterator over the elements of the heap.
      • clear

        void clear()
        Clears the contents of the heap.