Documentation
¶
Overview ¶
Package bstreelib: Basic Binary Search Tree Stuff
Index ¶
- type BinarySearchTree
- func (bst *BinarySearchTree[T]) BalanceTree() error
- func (bst *BinarySearchTree[T]) ConstructOrderedSlice() ([]T, error)
- func (bst *BinarySearchTree[T]) Count() (int, error)
- func (bst *BinarySearchTree[T]) Insert(value T) error
- func (bst *BinarySearchTree[T]) IsEmpty() bool
- func (bst *BinarySearchTree[T]) IsNil() bool
- func (bst *BinarySearchTree[T]) Root() *Node[T]
- func (bst *BinarySearchTree[T]) Search(val T) (bool, error)
- func (bst *BinarySearchTree[T]) TraverseBFS() (string, error)
- func (bst *BinarySearchTree[T]) TraverseDFSInOrder() (string, error)
- func (bst *BinarySearchTree[T]) TraverseDFSPostOrder() (string, error)
- func (bst *BinarySearchTree[T]) TraverseDFSPreOrder() (string, error)
- type BinarySearchTreeElement
- type Node
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BinarySearchTree ¶
type BinarySearchTree[T BinarySearchTreeElement] struct { // contains filtered or unexported fields }
BinarySearchTree struct will hold the core functionality of this library
func ConstructBalancedTree ¶
func ConstructBalancedTree[T BinarySearchTreeElement](values ...T) (*BinarySearchTree[T], error)
ConstructBalancedTree is a helper function to insert all the given values into a binary search tree, in a manner which creates a balanced tree
func ConstructFromValues ¶
func ConstructFromValues[T BinarySearchTreeElement](values ...T) (*BinarySearchTree[T], error)
ConstructFromValues is a helper function to insert all the given values (in the order that they are provided) into a binary search tree
func (*BinarySearchTree[T]) BalanceTree ¶
func (bst *BinarySearchTree[T]) BalanceTree() error
BalanceTree will re-arrange the binary tree into its most balanced form
func (*BinarySearchTree[T]) ConstructOrderedSlice ¶
func (bst *BinarySearchTree[T]) ConstructOrderedSlice() ([]T, error)
ConstructOrderedSlice collects all the elements in the binary search tree in an ordered manner, and returns them in a slice
func (*BinarySearchTree[T]) Count ¶
func (bst *BinarySearchTree[T]) Count() (int, error)
Count returns the number of elements in a binary search tree
func (*BinarySearchTree[T]) Insert ¶
func (bst *BinarySearchTree[T]) Insert(value T) error
Insert will add a new value to the binary search tree at the correct position
func (*BinarySearchTree[T]) IsEmpty ¶
func (bst *BinarySearchTree[T]) IsEmpty() bool
IsEmpty tells you if the binary search tree is empty
func (*BinarySearchTree[T]) IsNil ¶
func (bst *BinarySearchTree[T]) IsNil() bool
IsNil tells you if the pointer to the binary search tree is nil
func (*BinarySearchTree[T]) Root ¶
func (bst *BinarySearchTree[T]) Root() *Node[T]
Root returns a pointer to the root of a binary search tree
func (*BinarySearchTree[T]) Search ¶
func (bst *BinarySearchTree[T]) Search(val T) (bool, error)
Search looks for a given value the binary search tree, and tell you whether that value is present in the tree or not
func (*BinarySearchTree[T]) TraverseBFS ¶
func (bst *BinarySearchTree[T]) TraverseBFS() (string, error)
TraverseBFS returns a string that represents the traversal order of nodes using Breadth First Search
func (*BinarySearchTree[T]) TraverseDFSInOrder ¶
func (bst *BinarySearchTree[T]) TraverseDFSInOrder() (string, error)
TraverseDFSInOrder returns a string that represents the traversal order of nodes using Depth First Search In an in-order manner (visit a node's left subtree, then the node itself, followed by its right subtree) This method uses recursion
func (*BinarySearchTree[T]) TraverseDFSPostOrder ¶
func (bst *BinarySearchTree[T]) TraverseDFSPostOrder() (string, error)
func (*BinarySearchTree[T]) TraverseDFSPreOrder ¶
func (bst *BinarySearchTree[T]) TraverseDFSPreOrder() (string, error)
type BinarySearchTreeElement ¶
BinarySearchTreeElement is a custom interface that combines the constraints of the Ordered and Stringer interfaces
type Node ¶
type Node[T BinarySearchTreeElement] struct { // contains filtered or unexported fields }
Node is the basic unit of the binary search tree, and contains data which can be anything that implements the BinarySearchTreeElement interface
func (*Node[T]) RightChild ¶
RightChild is used to get a pointer to the right child of a given node