tree

package
v0.0.0-...-12cceb7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2020 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	Data interface{}

	Parent *Node

	Children []*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

func (u *Node) AppendChild(child *Node)

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

func (u *Node) Height() uint32

Height computes the height of the tree rooted at a given node. Takes time linear in the size of that subtree.

func (*Node) HeightRecursive

func (u *Node) HeightRecursive() uint32

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) IsLeaf

func (u *Node) IsLeaf() bool

IsLeaf returns true and if only if the specified node has no children.

func (*Node) IsRoot

func (u *Node) IsRoot() bool

IsRoot returns true if and only if the specified node has no parent.

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

func (u *Node) Size() uint32

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

func (u *Node) SizeRecursive() uint32

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL