Interface BinarySearchTree<T>

Type Parameters:
T - type of elements
All Superinterfaces:
Iterable<T>
All Known Implementing Classes:
AvlTree

public interface BinarySearchTree<T> extends Iterable<T>
Basic binary search tree collection which permits duplicates.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(T item)
    Adds an item to the tree.
    void
    Remove all elements from this tree.
    boolean
    contains(T item)
    Check if an item exists in the tree.
    int
    Check how many items are equal to item there are in the tree.
    Get an iterator over the elements in this tree, in descending order.
    greater(T item)
    Get the first item greater than item.
    int
    Get the height of this tree.
    boolean
    Returns true if tree has no elements.
    lesser(T item)
    Get the first item lesser than item.
    max()
    Get the maximum item.
    min()
    Get the minimum item.
    Get a detailed representation of the structure of this tree.
    void
    remove(T item)
    Removes an item to from the tree.
    int
    Get the current number of elements in the tree.
    Get a sequential stream over elements in this tree.

    Methods inherited from interface java.lang.Iterable

    forEach, iterator, spliterator
  • Method Details

    • isEmpty

      boolean isEmpty()
      Returns true if tree has no elements.
      Returns:
      true if tree has no elements.
    • size

      int size()
      Get the current number of elements in the tree.
      Returns:
      current number of elements
    • add

      void add(T item)
      Adds an item to the tree.
      Parameters:
      item - to be added
      Throws:
      ClassCastException - if item cannot be compared
    • remove

      void remove(T item)
      Removes an item to from the tree.
      Parameters:
      item - to be removed
      Throws:
      ClassCastException - if item cannot be compared
    • contains

      boolean contains(T item)
      Check if an item exists in the tree.
      Parameters:
      item - to check
      Returns:
      true if item exists in the tree
      Throws:
      ClassCastException - if item cannot be compared
    • containsCount

      int containsCount(T item)
      Check how many items are equal to item there are in the tree.
      Parameters:
      item - to check
      Returns:
      number of items equal to item
      Throws:
      ClassCastException - if item cannot be compared
    • height

      int height()
      Get the height of this tree.
      Returns:
      the current height of this tree
    • greater

      T greater(T item)
      Get the first item greater than item.
      Parameters:
      item - to check
      Returns:
      found greater item or null if no item is greater
      Throws:
      ClassCastException - if item cannot be compared
    • lesser

      T lesser(T item)
      Get the first item lesser than item.
      Parameters:
      item - to check
      Returns:
      found lesser item or null if no item is lesser
      Throws:
      ClassCastException - if item cannot be compared
    • min

      T min()
      Get the minimum item.
      Returns:
      minimum item
    • max

      T max()
      Get the maximum item.
      Returns:
      maximum item
    • prettyString

      String prettyString()
      Get a detailed representation of the structure of this tree.
      Returns:
      detailed pretty string
    • stream

      Stream<T> stream()
      Get a sequential stream over elements in this tree.
      Returns:
      a sequential stream over elements in this tree
    • clear

      void clear()
      Remove all elements from this tree.
    • descendingIterator

      Iterator<T> descendingIterator()
      Get an iterator over the elements in this tree, in descending order.
      Returns:
      descending order iterator over the elements in this tree