Class IdentifiableBinaryHeap<E extends Identifiable & java.lang.Comparable>

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Empties the queue.
      E deleteElementAt​(int index)  
      E deleteMin()
      Deletes the minimum element in the queue.
      int findElementIndex​(E element)  
      E findMin()
      Finds the minimum element in the queue.
      E getElement​(long id)
      Returns the element with the input ID, if the element exists; otherwise, returns null.
      void insert​(E element)
      Inserts an element into the queue.
      boolean isEmpty()
      Determines whether the queue is empty or not.
      E replaceElement​(long id, E newElement)
      Replace the old element of the specified id with a new element.
      void setIndex​(E element, int index)  
      int size()
      Returns the size of the queue.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • IdentifiableBinaryHeap

        public IdentifiableBinaryHeap()
      • IdentifiableBinaryHeap

        public IdentifiableBinaryHeap​(int initialCapacity)
    • Method Detail

      • replaceElement

        public E replaceElement​(long id,
                                E newElement)
        Description copied from interface: IdentifiablePriorityQueue
        Replace the old element of the specified id with a new element. The ID of the new element does not need to be the same as the old element. If the old element does not exist in the queue, then simply insert the new element into the queue.
        Specified by:
        replaceElement in interface IdentifiablePriorityQueue<E extends Identifiable & java.lang.Comparable>
        Parameters:
        id - ID of the old element
        newElement - new element
        Returns:
      • findElementIndex

        public int findElementIndex​(E element)
      • deleteElementAt

        public E deleteElementAt​(int index)
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: PriorityQueue
        Determines whether the queue is empty or not.
        Specified by:
        isEmpty in interface PriorityQueue<E extends Identifiable & java.lang.Comparable>
        Returns:
      • findMin

        public E findMin()
        Description copied from interface: PriorityQueue
        Finds the minimum element in the queue. This method is non-destructive peeking. The queue is left untouched.
        Specified by:
        findMin in interface PriorityQueue<E extends Identifiable & java.lang.Comparable>
        Returns:
        the minimum element in the queue. If the queue is empty, return null.
      • deleteMin

        public E deleteMin()
        Description copied from interface: PriorityQueue
        Deletes the minimum element in the queue.
        Specified by:
        deleteMin in interface PriorityQueue<E extends Identifiable & java.lang.Comparable>
        Returns:
        the minimum element in the queue. If the queue is empty, return null.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object