@@ -25,10 +25,9 @@ Base.convert(::Type{AVLNode{K,V}}, node::AVLNode) where {K,V} =
2525Construct an empty AVL Tree with keys of type `K`
2626and values of type `V`.
2727
28- AVLTree()
28+ AVLTree{K} ()
2929
30- Construct an empty AVL Tree that stores keys and values
31- of any type, alias for `AVLTree{Any,Any}()`.
30+ Construct an empty AVL tree with no values and keys of type `K`.
3231
3332The keys of AVL Tree must implement sorting operators (`>`, `<`)
3433and comparison operators (`=`, `≠`)
@@ -54,14 +53,20 @@ BinaryTrees.search(tree, 3) # right node
5453# delete nodes from the tree
5554BinaryTrees.delete!(tree, 1)
5655BinaryTrees.delete!(tree, 3)
56+
57+ # tree that only has keys
58+ tree = AVLTree{Int}()
59+ BinaryTrees.insert!(tree, 2) # root node
60+ BinaryTrees.insert!(tree, 1) # left node
61+ BinaryTrees.insert!(tree, 3) # right node
5762```
5863"""
5964mutable struct AVLTree{K,V} <: BinaryTree
6065 root:: Union{AVLNode{K,V},Nothing}
6166end
6267
6368AVLTree {K,V} () where {K,V} = AVLTree {K,V} (nothing )
64- AVLTree () = AVLTree {Any,Any } ()
69+ AVLTree {K} () where {K} = AVLTree {K,Nothing } ()
6570
6671search (tree:: AVLTree{K} , key:: K ) where {K} = _search (tree, key)
6772
@@ -70,6 +75,8 @@ function insert!(tree::AVLTree{K}, key::K, value) where {K}
7075 tree
7176end
7277
78+ insert! (tree:: AVLTree{K,Nothing} , key:: K ) where {K} = insert! (tree, key, nothing )
79+
7380function delete! (tree:: AVLTree{K} , key:: K ) where {K}
7481 tree. root = _delete! (tree. root, key)
7582 tree
0 commit comments