Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRootValue ¶
GetRootValue returns the value of the root node. If the tree is nil, returns the zero value of the type.
Types ¶
type AvlTree ¶
AvlTree struct for an AVL Tree of any ordered type. This is a self-balancing binary tree. The difference between the heights of the left and right subtree cannot be more than one for all nodes. For more information about theory, see https://en.wikipedia.org/wiki/AVL_tree
func Delete ¶
Delete the value in the tree. If the tree is nil, it returns nil. If the value is equal to the root, it deletes the root. If the value is less than the root, it deletes in the left subtree. If the value is greater than the root, it deletes in the right subtree. After deleting, it rebalances the tree. It returns the new root of the tree.
func Insert ¶
Insert a value in the tree. If the tree is nil, it creates a new node with the value. If the value is already in the tree, it does nothing. If the value is less than the root, it inserts in the left subtree. If the value is greater than the root, it inserts in the right subtree. After inserting, it rebalances the tree. It returns the new root of the tree.
func NewAvlTree ¶
NewAvlTree is factory function for avlTree struct. Return a nil pointer to avlTree.