Documentation ¶
Overview ¶
Package binarysearchtree provides functions to create/work with generic binary search trees.
Index ¶
- type BinarySearchTree
- func (bts *BinarySearchTree[T]) Find(v T) (n *Node[T], found bool)
- func (bts *BinarySearchTree[T]) Height() int
- func (bts *BinarySearchTree[T]) Insert(v T)
- func (bts *BinarySearchTree[T]) NodeDepth(n *Node[T]) int
- func (bts *BinarySearchTree[T]) NodeHeight(n *Node[T]) int
- func (bts *BinarySearchTree[T]) Remove(n *Node[T])
- func (bts *BinarySearchTree[T]) Root() *Node[T]
- func (bts *BinarySearchTree[T]) Size() int
- type Node
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BinarySearchTree ¶
type BinarySearchTree[T constraints.Ordered] struct { // contains filtered or unexported fields }
BinarySearchTree is a binary search tree of an ordered type T.
func New ¶
func New[T constraints.Ordered]() *BinarySearchTree[T]
New creates a binary search tree of a constraints.Ordered type T.
func (*BinarySearchTree[T]) Find ¶
func (bts *BinarySearchTree[T]) Find(v T) (n *Node[T], found bool)
Find returns the node of the binary search value that has a specific value.
func (*BinarySearchTree[T]) Height ¶
func (bts *BinarySearchTree[T]) Height() int
Height returns the number of edges between the root of the tree and its deepest descendent, i.e. the height of the root.
func (*BinarySearchTree[T]) Insert ¶
func (bts *BinarySearchTree[T]) Insert(v T)
Insert adds a value to the binary search tree.
func (*BinarySearchTree[T]) NodeDepth ¶
func (bts *BinarySearchTree[T]) NodeDepth(n *Node[T]) int
NodeDepth returns the number of edges from the root of the tree to a node (the depth of a node).
func (*BinarySearchTree[T]) NodeHeight ¶
func (bts *BinarySearchTree[T]) NodeHeight(n *Node[T]) int
NodeHeight returns the number of edges from a node to its deepest descendent (the height of a node).
func (*BinarySearchTree[T]) Remove ¶
func (bts *BinarySearchTree[T]) Remove(n *Node[T])
Remove removes a node from the binary search tree.
func (*BinarySearchTree[T]) Root ¶
func (bts *BinarySearchTree[T]) Root() *Node[T]
Root returns the root of the binary search tree.
func (*BinarySearchTree[T]) Size ¶
func (bts *BinarySearchTree[T]) Size() int
Size returns the number of nodes in the binary search tree.
type Node ¶
type Node[T comparable] struct { // contains filtered or unexported fields }
Node is a node of a binary search tree.