Interface BinarySearchTree<T>
- Type Parameters:
T
- type of elements
- All Superinterfaces:
Iterable<T>
- All Known Implementing Classes:
AvlTree
Basic binary search tree collection which permits duplicates.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an item to the tree.void
clear()
Remove all elements from this tree.boolean
Check if an item exists in the tree.int
containsCount
(T item) Check how many items are equal toitem
there are in the tree.Get an iterator over the elements in this tree, in descending order.Get the first item greater thanitem
.int
height()
Get the height of this tree.boolean
isEmpty()
Returns true if tree has no elements.Get the first item lesser thanitem
.max()
Get the maximum item.min()
Get the minimum item.Get a detailed representation of the structure of this tree.void
Removes an item to from the tree.int
size()
Get the current number of elements in the tree.stream()
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
Adds an item to the tree.- Parameters:
item
- to be added- Throws:
ClassCastException
- if item cannot be compared
-
remove
Removes an item to from the tree.- Parameters:
item
- to be removed- Throws:
ClassCastException
- if item cannot be compared
-
contains
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
Check how many items are equal toitem
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
Get the first item greater thanitem
.- Parameters:
item
- to check- Returns:
- found greater item or null if no item is greater
- Throws:
ClassCastException
- if item cannot be compared
-
lesser
Get the first item lesser thanitem
.- 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
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
Get an iterator over the elements in this tree, in descending order.- Returns:
- descending order iterator over the elements in this tree
-