public class AVLTree<K,V> extends BinarySearchTree<K,V> implements Dictionary<K,V>
Modifier and Type | Class and Description |
---|---|
protected static class |
AVLTree.AVLNode<K,V>
Nested class for the nodes of an AVL tree.
|
BinarySearchTree.BSTEntry<K,V>
actionPos, C, numEntries
root, size
Constructor and Description |
---|
AVLTree() |
AVLTree(java.util.Comparator<K> c) |
Modifier and Type | Method and Description |
---|---|
protected BTPosition<Entry<K,V>> |
createNode(Entry<K,V> element,
BTPosition<Entry<K,V>> parent,
BTPosition<Entry<K,V>> left,
BTPosition<Entry<K,V>> right)
Creates a new binary search tree node (overrides super's version).
|
protected int |
height(Position<Entry<K,V>> p)
Returns the height of a node (call back to an AVLNode).
|
Entry<K,V> |
insert(K k,
V v)
Inserts an item into the dictionary and returns the newly created
entry.
|
protected boolean |
isBalanced(Position<Entry<K,V>> p)
Returns whether a node has balance factor between -1 and 1.
|
protected void |
rebalance(Position<Entry<K,V>> zPos)
Rebalance method called by insert and remove.
|
Entry<K,V> |
remove(Entry<K,V> ent)
Removes and returns an entry from the dictionary.
|
protected void |
setHeight(Position<Entry<K,V>> p)
Sets the height of an internal node (call back to an AVLNode).
|
protected Position<Entry<K,V>> |
tallerChild(Position<Entry<K,V>> p)
Return a child of p with height no smaller than that of the
other child.
|
addAll, checkEntry, checkKey, entries, entry, find, findAll, insertAtExternal, isEmpty, key, removeExternal, replaceEntry, restructure, size, treeSearch, value
addRoot, attach, checkPosition, children, expandExternal, hasLeft, hasRight, inorderPositions, insertLeft, insertRight, isExternal, isInternal, isRoot, iterator, left, parent, positions, preorderPositions, remove, removeAboveExternal, replace, right, root, sibling, swapElements
public AVLTree(java.util.Comparator<K> c)
public AVLTree()
protected BTPosition<Entry<K,V>> createNode(Entry<K,V> element, BTPosition<Entry<K,V>> parent, BTPosition<Entry<K,V>> left, BTPosition<Entry<K,V>> right)
createNode
in class LinkedBinaryTree<Entry<K,V>>
protected int height(Position<Entry<K,V>> p)
protected void setHeight(Position<Entry<K,V>> p)
protected boolean isBalanced(Position<Entry<K,V>> p)
protected Position<Entry<K,V>> tallerChild(Position<Entry<K,V>> p)
protected void rebalance(Position<Entry<K,V>> zPos)
public Entry<K,V> insert(K k, V v) throws InvalidKeyException
insert
in interface Dictionary<K,V>
insert
in class BinarySearchTree<K,V>
InvalidKeyException
public Entry<K,V> remove(Entry<K,V> ent) throws InvalidEntryException
remove
in interface Dictionary<K,V>
remove
in class BinarySearchTree<K,V>
InvalidEntryException