Documentation
¶
Index ¶
- type Node
- func (u *Node) AppendChild(child *Node)
- func (u *Node) Height() uint32
- func (u *Node) HeightRecursive() uint32
- func (u *Node) IsLeaf() bool
- func (u *Node) IsRoot() bool
- func (u *Node) PostOrderTraversal(callback callbackFunc)
- func (u *Node) PostOrderTraversalRecursive(callback callbackFunc)
- func (u *Node) PreOrderTraversal(callback callbackFunc)
- func (u *Node) PreOrderTraversalRecursive(callback callbackFunc)
- func (u *Node) Size() uint32
- func (u *Node) SizeRecursive() uint32
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
Node represents a node in a rooted ordered tree.
func New ¶
func New(data interface{}) *Node
New creates a new bare node holding any desired sort of data.
func (*Node) AppendChild ¶
AppendChild creates a parent-child relationship between an input node and another given node, appending it to its ordered list of children.
func (*Node) Height ¶
Height computes the height of the tree rooted at a given node. Takes time linear in the size of that subtree.
func (*Node) HeightRecursive ¶
HeightRecursive computes the height of the tree rooted at a given node, using a recursive function call. Takes time linear in the size of that subtree.
func (*Node) PostOrderTraversal ¶
func (u *Node) PostOrderTraversal(callback callbackFunc)
PostOrderTraversal performs post-order traversal of the tree rooted at a given node, applying the callback function on each node after its children. This method uses a stack explicitly to track the nodes in the traversal.
func (*Node) PostOrderTraversalRecursive ¶
func (u *Node) PostOrderTraversalRecursive(callback callbackFunc)
PostOrderTraversal performs post-order traversal of the tree rooted at a given node, applying the callback function on each node after its children. This method recursively calls itself in order to perform the traversal.
func (*Node) PreOrderTraversal ¶
func (u *Node) PreOrderTraversal(callback callbackFunc)
PreOrderTraversal performs pre-order traversal of the tree rooted at a given node, applying the callback function on each node before its children. This method uses a stack explicitly to track the nodes in the traversal.
func (*Node) PreOrderTraversalRecursive ¶
func (u *Node) PreOrderTraversalRecursive(callback callbackFunc)
PreOrderTraversalRecursive performs pre-order traversal of the tree rooted at a given node, applying the callback function on each node before its children. This method recursively calls itself in order to perform the traversal.
func (*Node) Size ¶
Size computes the number of nodes in the subtree rooted at a given node. Takes time linear in the size of the subtree.
func (*Node) SizeRecursive ¶
SizeRecursive computes the number of nodes in the subtree rooted at a given node, using a recursive function call. Takes time linear in the size of the subtree.