Documentation
¶
Index ¶
- func IntComparator(a, b int) int
- func StringComparator(a, b string) int
- type ComparatorFunc
- type FindFunc
- type Node
- func (n *Node[T]) AddAttribute(name, value string)
- func (n *Node[T]) AddSkipNodeFunc(handler SkipNodeFunc[T])
- func (n *Node[T]) FindNode(predicate FindFunc[T]) (*Node[T], bool)
- func (n *Node[T]) GetDotAttributes() string
- func (n *Node[T]) Height() int
- func (n *Node[T]) InsertLeft(value T) *Node[T]
- func (n *Node[T]) InsertRight(value T) *Node[T]
- func (n *Node[T]) IsBalancedTree() bool
- func (n *Node[T]) IsBinarySearchTree(comparator ComparatorFunc[T]) bool
- func (n *Node[T]) IsCompleteTree() bool
- func (n *Node[T]) IsDegenerateTree() bool
- func (n *Node[T]) IsFullNode() bool
- func (n *Node[T]) IsFullTree() bool
- func (n *Node[T]) IsLeafNode() bool
- func (n *Node[T]) IsPerfectTree() bool
- func (n *Node[T]) Size() int
- func (n *Node[T]) WalkInOrder(walkFunc WalkFunc[T]) error
- func (n *Node[T]) WalkLevelOrder(walkFunc WalkFunc[T]) error
- func (n *Node[T]) WalkPostOrder(walkFunc WalkFunc[T]) error
- func (n *Node[T]) WalkPreOrder(walkFunc WalkFunc[T]) error
- func (n *Node[T]) WriteDot(w io.Writer) error
- type SkipNodeFunc
- type WalkFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IntComparator ¶
IntComparator is a comparator function for comparing integer node values.
func StringComparator ¶
StringComparator is a comparator function for comparing string node values.
Types ¶
type ComparatorFunc ¶
ComparatorFunc is a function which compares two values of type T. The comparator function should return:
- A negative integer when A is less than B - A positive integer when A is greater than B - Zero when A equals B
The comparator function is used by IsBinarySearchTree method for validating whether a given binary tree is a Binary Search Tree (BST).
type FindFunc ¶
FindFunc is the type of the function predicate which will be invoked for each node while looking for a given node. The function should return true, if the node is the one we are looking for, false otherwise.
type Node ¶
type Node[T any] struct { // Value is the value of the node Value T // Left child of the node Left *Node[T] // Right child of the node Right *Node[T] // contains filtered or unexported fields }
Node represents a node from a binary tree
func (*Node[T]) AddAttribute ¶
AddAttribute associates an attribute with the node, which will be used when generating the Dot representation of the tree.
func (*Node[T]) AddSkipNodeFunc ¶
func (n *Node[T]) AddSkipNodeFunc(handler SkipNodeFunc[T])
AddSkipNodeFunc adds a new handler for determining whether a node from the tree should be skipped while traversing it.
func (*Node[T]) GetDotAttributes ¶
GetDotAttributes returns the attributes associated with the node in format suitable for using in the Dot representation.
func (*Node[T]) InsertLeft ¶
InsertLeft inserts a new node to the left
func (*Node[T]) InsertRight ¶
InsertRight inserts a new node to the right
func (*Node[T]) IsBalancedTree ¶
IsBalancedTree returns true, if the tree is balanced. A balanced tree is such a tree, for which the height of the left and right sub-trees of each node differ by no more than 1.
func (*Node[T]) IsBinarySearchTree ¶
func (n *Node[T]) IsBinarySearchTree(comparator ComparatorFunc[T]) bool
IsBinarySearchTree returns true, if the tree is a Binary Search Tree (BST).
func (*Node[T]) IsCompleteTree ¶
IsCompleteTree returns true, if the tree is complete. A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible.
func (*Node[T]) IsDegenerateTree ¶
IsDegenerateTree returns true, if each parent has only one child node.
func (*Node[T]) IsFullNode ¶
IsFullNode returns true, if the node contains left and right children
func (*Node[T]) IsFullTree ¶
IsFullTree returns true, if the binary tree is full. A full binary tree is a tree in which every node has either 0 or 2 children.
func (*Node[T]) IsLeafNode ¶
IsLeafNode returns true, if the node is a leaf, false otherwise.
func (*Node[T]) IsPerfectTree ¶
IsPerfectTree returns true, if the binary tree is full and complete
func (*Node[T]) WalkInOrder ¶
WalkInOrder performs an iterative In-order walking of the binary tree - Left-Node-Right (LNR)
func (*Node[T]) WalkLevelOrder ¶
WalkLevelOrder performs an iterative Level-order (Breadth-first) walking of the binary tree.
func (*Node[T]) WalkPostOrder ¶
WalkPostOrder performs an iterative Post-order walking of the binary tree - Left-Right-Node (LRN)
func (*Node[T]) WalkPreOrder ¶
WalkPreOrder performs an iterative Pre-order walking of the binary tree - Node-Left-Right (NLR)
type SkipNodeFunc ¶
SkipNodeFunc is a function which returns true, if the currently being visited node should be skipped.