T
- the type of the elements@Deprecated public class AVLTree<T extends Comparable<T>> extends Object
The purpose of this class is to sort elements while allowing
duplicate elements (i.e. such that a.equals(b)
is
true). The SortedSet
interface does not allow this, so
a specific class is needed. Null elements are not allowed.
Since the equals
method is not sufficient to
differentiate elements, the delete
method is
implemented using the equality operator.
In order to clearly mark the methods provided here do not have
the same semantics as the ones specified in the
SortedSet
interface, different names are used
(add
has been replaced by insert
and
remove
has been replaced by delete
).
This class is based on the C implementation Georg Kraml has put in the public domain. Unfortunately, his page seems not to exist any more.
Modifier and Type | Class and Description |
---|---|
class |
AVLTree.Node
Deprecated.
This class implements AVL trees nodes.
|
Constructor and Description |
---|
AVLTree()
Deprecated.
Build an empty tree.
|
Modifier and Type | Method and Description |
---|---|
boolean |
delete(T element)
Deprecated.
Delete an element from the tree.
|
AVLTree.Node |
getLargest()
Deprecated.
Get the node whose element is the largest one in the tree.
|
AVLTree.Node |
getNotLarger(T reference)
Deprecated.
Get the node whose element is not larger than the reference object.
|
AVLTree.Node |
getNotSmaller(T reference)
Deprecated.
Get the node whose element is not smaller than the reference object.
|
AVLTree.Node |
getSmallest()
Deprecated.
Get the node whose element is the smallest one in the tree.
|
void |
insert(T element)
Deprecated.
Insert an element in the tree.
|
boolean |
isEmpty()
Deprecated.
Check if the tree is empty.
|
int |
size()
Deprecated.
Get the number of elements of the tree.
|
public void insert(T element)
element
- element to insert (silently ignored if null)public boolean delete(T element)
The element is deleted only if there is a node n
containing exactly the element instance specified, i.e. for which
n.getElement() == element
. This is purposely
different from the specification of the
java.util.Set
remove
method (in fact,
this is the reason why a specific class has been developed).
element
- element to delete (silently ignored if null)public boolean isEmpty()
public int size()
public AVLTree.Node getSmallest()
getLargest()
,
getNotSmaller(T)
,
getNotLarger(T)
,
AVLTree.Node.getPrevious()
,
AVLTree.Node.getNext()
public AVLTree.Node getLargest()
getSmallest()
,
getNotSmaller(T)
,
getNotLarger(T)
,
AVLTree.Node.getPrevious()
,
AVLTree.Node.getNext()
public AVLTree.Node getNotSmaller(T reference)
reference
- reference object (may not be in the tree)getSmallest()
,
getLargest()
,
getNotLarger(T)
,
AVLTree.Node.getPrevious()
,
AVLTree.Node.getNext()
public AVLTree.Node getNotLarger(T reference)
reference
- reference object (may not be in the tree)getSmallest()
,
getLargest()
,
getNotSmaller(T)
,
AVLTree.Node.getPrevious()
,
AVLTree.Node.getNext()
Copyright © 2003–2016 The Apache Software Foundation. All rights reserved.