Documentation
¶
Index ¶
- func EqualTree[T constraints.Ordered](p, q *BinaryTree[T]) bool
- type BinaryTree
- func (self *BinaryTree[T]) Count() int
- func (BT *BinaryTree[T]) Height() int
- func (BT *BinaryTree[T]) Invert()
- func (self *BinaryTree[T]) IsEmpty() bool
- func (BT *BinaryTree[T]) TranverseInOrder(process func(T))
- func (BT *BinaryTree[T]) TranverseLevelOrder(process func(T))
- func (BT *BinaryTree[T]) TranversePostOrder(process func(T))
- func (BT *BinaryTree[T]) TranversePreOrder(process func(T))
- type BinaryTreeNode
- func (self *BinaryTreeNode[T]) Count() int
- func (self *BinaryTreeNode[T]) Depth() int
- func (self *BinaryTreeNode[T]) HasAnyChildren() bool
- func (self *BinaryTreeNode[T]) HasBothChildren() bool
- func (self *BinaryTreeNode[T]) HasLeftChild() bool
- func (self *BinaryTreeNode[T]) HasRightChild() bool
- func (self *BinaryTreeNode[T]) Height() int
- func (self *BinaryTreeNode[T]) Invert()
- func (self *BinaryTreeNode[T]) IsLeaf() bool
- func (self *BinaryTreeNode[T]) IsLeftChild() bool
- func (self *BinaryTreeNode[T]) IsRightChild() bool
- func (self *BinaryTreeNode[T]) IsRoot() bool
- func (self *BinaryTreeNode[T]) IterInOrder(process func(T))
- func (self *BinaryTreeNode[T]) IterPostOrder(process func(T))
- func (self *BinaryTreeNode[T]) IterPreOrder(process func(T))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EqualTree ¶
func EqualTree[T constraints.Ordered](p, q *BinaryTree[T]) bool
Public Static Function that comapres two nodes and returns True if they're equal. False otherwise.
Types ¶
type BinaryTree ¶
type BinaryTree[T constraints.Ordered] struct { // contains filtered or unexported fields }
Binary Tree Struct
func BinaryTreeInit ¶
func BinaryTreeInit[T constraints.Ordered](values ...T) *BinaryTree[T]
Constructor Function to return a new Binary Tree.
func (*BinaryTree[T]) Count ¶
func (self *BinaryTree[T]) Count() int
Method to return the distance of node to it's lowest leaf. Runs in O(h) time.
func (*BinaryTree[T]) Height ¶
func (BT *BinaryTree[T]) Height() int
Method to return the largest # of edges in a path from the tree's root to a leaf node.
func (*BinaryTree[T]) IsEmpty ¶
func (self *BinaryTree[T]) IsEmpty() bool
Method to return True if tree is currently empty (rootless). False otherwise.
func (*BinaryTree[T]) TranverseInOrder ¶
func (BT *BinaryTree[T]) TranverseInOrder(process func(T))
Method to Iterate node in inorder order (left, node, right).
func (*BinaryTree[T]) TranverseLevelOrder ¶
func (BT *BinaryTree[T]) TranverseLevelOrder(process func(T))
Method to Iterate node in postorder order (left, right, node).
func (*BinaryTree[T]) TranversePostOrder ¶
func (BT *BinaryTree[T]) TranversePostOrder(process func(T))
Method to Iterate node in postorder order (left, right, node).
func (*BinaryTree[T]) TranversePreOrder ¶
func (BT *BinaryTree[T]) TranversePreOrder(process func(T))
Method to Iterate tree in preorder order (node, left, right).
type BinaryTreeNode ¶
type BinaryTreeNode[T constraints.Ordered] struct { // contains filtered or unexported fields }
Binary Tree's Node Struct
func (*BinaryTreeNode[T]) Count ¶
func (self *BinaryTreeNode[T]) Count() int
Method to return number of subnodes. Runs in O(n) time.
func (*BinaryTreeNode[T]) Depth ¶
func (self *BinaryTreeNode[T]) Depth() int
Method to return the distance of node from the root. Runs in O(h) time.
func (*BinaryTreeNode[T]) HasAnyChildren ¶
func (self *BinaryTreeNode[T]) HasAnyChildren() bool
Method to return True if node Has a left or right child (if HasLeftChild || HasRightChild). False if otherwise.
func (*BinaryTreeNode[T]) HasBothChildren ¶
func (self *BinaryTreeNode[T]) HasBothChildren() bool
Method to return True if node Has both children (if HasLeftChild && HasRightChild). False if otherwise.
func (*BinaryTreeNode[T]) HasLeftChild ¶
func (self *BinaryTreeNode[T]) HasLeftChild() bool
Method to return True if node Has a left child (if node.left != nil). False if otherwise.
func (*BinaryTreeNode[T]) HasRightChild ¶
func (self *BinaryTreeNode[T]) HasRightChild() bool
Method to return True if node Has a right child (if node.right != nil). False if otherwise.
func (*BinaryTreeNode[T]) Height ¶
func (self *BinaryTreeNode[T]) Height() int
Method to return the distance of node to it's lowest leaf. Runs in O(h) time.
func (*BinaryTreeNode[T]) Invert ¶
func (self *BinaryTreeNode[T]) Invert()
Method to reverse node (left, node, right) -> (right, node, left)
func (*BinaryTreeNode[T]) IsLeaf ¶
func (self *BinaryTreeNode[T]) IsLeaf() bool
Method to return True if node is a leaf node (Has no left or right). False if otherwise.
func (*BinaryTreeNode[T]) IsLeftChild ¶
func (self *BinaryTreeNode[T]) IsLeftChild() bool
Method to return True if node is a left child (if parent.left == node). False if otherwise.
func (*BinaryTreeNode[T]) IsRightChild ¶
func (self *BinaryTreeNode[T]) IsRightChild() bool
Method to return True if node is a right child (if parent.right == node). False if otherwise.
func (*BinaryTreeNode[T]) IsRoot ¶
func (self *BinaryTreeNode[T]) IsRoot() bool
Method to return True if node is root (Has no parent node). False otherwise.
func (*BinaryTreeNode[T]) IterInOrder ¶
func (self *BinaryTreeNode[T]) IterInOrder(process func(T))
Method to Iterate node in inorder order (left, node, right)
func (*BinaryTreeNode[T]) IterPostOrder ¶
func (self *BinaryTreeNode[T]) IterPostOrder(process func(T))
Method to Iterate node in postorder order (left, right, node)
func (*BinaryTreeNode[T]) IterPreOrder ¶
func (self *BinaryTreeNode[T]) IterPreOrder(process func(T))
Method to Iterate node in preorder order (node, left, right)