Class AvlTree<T>
java.lang.Object
com.abstractkamen.datastructures.impl.trees.search.AvlTree<T>
- Type Parameters:
T- type of elements
- All Implemented Interfaces:
BinarySearchTree<T>,Iterable<T>
An AVL implementation of the BinarySearchTree interface. Currently, does not support concurrent modification.
-
Constructor Summary
ConstructorsConstructorDescriptionAvlTree(Comparator<T> comparator) Create anAvlTree<T>with a custom comparator and allowed duplicate values.AvlTree(Comparator<T> comparator, boolean allowDuplicates) Create anAvlTree<T>with a custom comparator and flag for duplicate values. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an item to the tree.voidclear()Remove all elements from this tree.booleanCheck if an item exists in the tree.intcontainsCount(T item) Check how many items are equal toitemthere are in the tree.static <T extends Comparable<T>>
AvlTree<T>Create anAvlTree<T>with natural order comparator in a type safe way.static <T extends Comparable<T>>
AvlTree<T>createComparable(boolean allowDuplicates) Create anAvlTree<T>with natural order comparator in a type safe way and flag for duplicate values.Get an iterator over the elements in this tree, in descending order.Get the first item greater thanitem.intheight()Get the height of this tree.booleanisEmpty()Returns true if tree has no elements.iterator()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.voidRemoves an item to from the tree.intsize()Get the current number of elements in the tree.stream()Get a sequential stream over elements in this tree.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
AvlTree
Create anAvlTree<T>with a custom comparator and allowed duplicate values.- Parameters:
comparator- custom comparator
-
AvlTree
Create anAvlTree<T>with a custom comparator and flag for duplicate values.- Parameters:
comparator- custom comparatorallowDuplicates- flag for duplicate values
-
-
Method Details
-
createComparable
Create anAvlTree<T>with natural order comparator in a type safe way.- Type Parameters:
T- comparable type
-
createComparable
Create anAvlTree<T>with natural order comparator in a type safe way and flag for duplicate values.- Type Parameters:
T- comparable type- Parameters:
allowDuplicates- flag for duplicate values
-
isEmpty
public boolean isEmpty()Description copied from interface:BinarySearchTreeReturns true if tree has no elements.- Specified by:
isEmptyin interfaceBinarySearchTree<T>- Returns:
- true if tree has no elements.
-
size
public int size()Description copied from interface:BinarySearchTreeGet the current number of elements in the tree.- Specified by:
sizein interfaceBinarySearchTree<T>- Returns:
- current number of elements
-
add
Description copied from interface:BinarySearchTreeAdds an item to the tree.- Specified by:
addin interfaceBinarySearchTree<T>- Parameters:
item- to be added
-
remove
Description copied from interface:BinarySearchTreeRemoves an item to from the tree.- Specified by:
removein interfaceBinarySearchTree<T>- Parameters:
item- to be removed
-
contains
Description copied from interface:BinarySearchTreeCheck if an item exists in the tree.- Specified by:
containsin interfaceBinarySearchTree<T>- Parameters:
item- to check- Returns:
- true if item exists in the tree
-
containsCount
Description copied from interface:BinarySearchTreeCheck how many items are equal toitemthere are in the tree.- Specified by:
containsCountin interfaceBinarySearchTree<T>- Parameters:
item- to check- Returns:
- number of items equal to
item
-
height
public int height()Description copied from interface:BinarySearchTreeGet the height of this tree.- Specified by:
heightin interfaceBinarySearchTree<T>- Returns:
- the current height of this tree
-
greater
Description copied from interface:BinarySearchTreeGet the first item greater thanitem.- Specified by:
greaterin interfaceBinarySearchTree<T>- Parameters:
item- to check- Returns:
- found greater item or null if no item is greater
-
lesser
Description copied from interface:BinarySearchTreeGet the first item lesser thanitem.- Specified by:
lesserin interfaceBinarySearchTree<T>- Parameters:
item- to check- Returns:
- found lesser item or null if no item is lesser
-
min
Description copied from interface:BinarySearchTreeGet the minimum item.- Specified by:
minin interfaceBinarySearchTree<T>- Returns:
- minimum item
-
max
Description copied from interface:BinarySearchTreeGet the maximum item.- Specified by:
maxin interfaceBinarySearchTree<T>- Returns:
- maximum item
-
prettyString
Description copied from interface:BinarySearchTreeGet a detailed representation of the structure of this tree.- Specified by:
prettyStringin interfaceBinarySearchTree<T>- Returns:
- detailed pretty string
-
stream
Description copied from interface:BinarySearchTreeGet a sequential stream over elements in this tree.- Specified by:
streamin interfaceBinarySearchTree<T>- Returns:
- a sequential stream over elements in this tree
-
clear
public void clear()Description copied from interface:BinarySearchTreeRemove all elements from this tree.- Specified by:
clearin interfaceBinarySearchTree<T>
-
descendingIterator
Description copied from interface:BinarySearchTreeGet an iterator over the elements in this tree, in descending order.- Specified by:
descendingIteratorin interfaceBinarySearchTree<T>- Returns:
- descending order iterator over the elements in this tree
-
iterator
-
toString
-