Package aud
Class AVLTree<Key extends Comparable<Key>,Value>
java.lang.Object
aud.BinarySearchTree<Key,Value>
aud.AVLTree<Key,Value>
- All Implemented Interfaces:
Graphvizable,GraphvizDecorable,Iterable<BinarySearchTree<Key,Value>.Cursor>
Simple implementation of an AVL tree.
This implementation is based on BinarySearchTree and in
particular BinarySearchTree.restructure(aud.BinarySearchTree.Node) for rebalancing.
This implementation does not implement removal of nodes!
remove(Key) always throws
UnsupportedOperationException!
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class aud.BinarySearchTree
BinarySearchTree.Cursor, BinarySearchTree.Decorator, BinarySearchTree.Entry, BinarySearchTree.Iterator, BinarySearchTree.LowerBound, BinarySearchTree.Node, BinarySearchTree.Range, BinarySearchTree.RangeIterator, BinarySearchTree.Visitor -
Field Summary
Fields inherited from class aud.BinarySearchTree
head_ -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckConsistency(BinarySearchTree<Key, Value>.Node node) additionally check heights and balancingprotected BinarySearchTree<Key,Value>.Node createNode(Key key, Value value) override: create new AVLNodeintget height of treestatic voidexample and testprotected voidonInsert(BinarySearchTree<Key, Value>.Node _node) Called whenever a new node is inserted.protected voidnot implemented!Methods inherited from class aud.BinarySearchTree
checkConsistency, compareKeys, find, findEntry, findLowerBound, getDecorator, getMaximum, getMinimum, insert, isEmpty, iterator, onRemove, range, removeNode, restructure, restructure, rotateLeft, rotateLeftRight, rotateRight, rotateRightLeft, setupBalancedSubtree, toDot, toString, toText, toTikZ, visitPreorderMethods 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
public AVLTree()create empty tree
-
-
Method Details
-
createNode
override: create new AVLNode- Overrides:
createNodein classBinarySearchTree<Key extends Comparable<Key>,Value>
-
getHeight
public int getHeight()get height of tree -
onInsert
Description copied from class:BinarySearchTreeCalled whenever a new node is inserted.Called by
BinarySearchTree.insert(Key, Value)to notify a class derived fromBinarySearchTreethat a new node has been inserted. Using this sort of callback mechanism avoids a reimplementation ofBinarySearchTree.insert(Key, Value).The standard implementation is empty. The idea is to use the callback for visualization or have a subclass rebalancing the tree after node insertion.
- Overrides:
onInsertin classBinarySearchTree<Key extends Comparable<Key>,Value> - Parameters:
_node- the newly inserted node
-
rebalance
-
remove
not implemented!- Overrides:
removein classBinarySearchTree<Key extends Comparable<Key>,Value> - Returns:
- value of removed node or
nullif there was no such node - Throws:
UnsupportedOperationException- always!
-
checkConsistency
additionally check heights and balancing- Overrides:
checkConsistencyin classBinarySearchTree<Key extends Comparable<Key>,Value>
-
main
example and test
-