Class BinarySearchTree<E extends java.lang.Comparable<E>>

  • All Implemented Interfaces:
    PriorityQueue<E>

    public class BinarySearchTree<E extends java.lang.Comparable<E>>
    extends java.lang.Object
    implements PriorityQueue<E>
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      E deleteMin()
      Remove and return the smallest item from the priority queue.
      E findMin()
      Retrieve (but not remove) the smallest item in the queue.
      void insert​(E x)
      Insert the given element into the queue.
      boolean isEmpty()
      Check if the priority queue is empty.
      void remove​(E x)
      Remove the given element from the priority queue.
      int size()
      Get the number of elements in this queue.
      • Methods inherited from class java.lang.Object

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

      • BinarySearchTree

        public BinarySearchTree()
        Create a new empty binary search tree.
      • BinarySearchTree

        public BinarySearchTree​(BinarySearchTree<E> bst)
        Create a copy of the given binary search tree.
        Parameters:
        bst - Binary search tree to copy.
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Description copied from interface: PriorityQueue
        Check if the priority queue is empty.

        Complexity: O(1)

        Specified by:
        isEmpty in interface PriorityQueue<E extends java.lang.Comparable<E>>
        Returns:
        true if the queue is empty, false otherwise.
      • size

        public int size()
        Description copied from interface: PriorityQueue
        Get the number of elements in this queue.

        Complexity: O(1)

        Specified by:
        size in interface PriorityQueue<E extends java.lang.Comparable<E>>
        Returns:
        Current size (number of elements) of this queue.
      • insert

        public void insert​(E x)
        Description copied from interface: PriorityQueue
        Insert the given element into the queue.

        Complexity: O(log n)

        Specified by:
        insert in interface PriorityQueue<E extends java.lang.Comparable<E>>
        Parameters:
        x - Item to insert.