tree

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 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 TNode

type TNode struct {
	// The value of the node.
	Val interface{}
	// contains filtered or unexported fields
}

Tree node in a cross doubly linked list structure.

func (*TNode) AppendTo

func (node *TNode) AppendTo(parent *TNode) bool

AppendTo appends the node to the specified new parent as the last child. It will be removed from the children of the original parent node, if exists.

[PARAMETERS]

parent *TNode // The new parent. If this is nil, it will make the node parentless.

[RETURNS]

bool // If the operation succeeds, it is true, otherwise it means that the node is nil.

func (*TNode) Children

func (node *TNode) Children() []*TNode

Children returns a list of all children of the node. A nil value means that it does not have any child.

func (*TNode) FirstChild

func (node *TNode) FirstChild() *TNode

FirstChild returns the first child of the node. A nil value means that it does not exist.

func (*TNode) LastChild

func (node *TNode) LastChild() *TNode

LastChild returns the last child of the node. A nil value means that it does not exist.

func (*TNode) Next

func (node *TNode) Next() *TNode

Next returns the next sibling of the node. A nil value means that it does not exist.

func (*TNode) Parent

func (node *TNode) Parent() *TNode

Parent returns the parent of the node. A nil value means that it does not exist.

func (*TNode) Prev

func (node *TNode) Prev() *TNode

Prev returns the previous sibling of the node. A nil value means that it does not exist.

type Tree

type Tree = *TNode

Points to the root of which tree it represents.

func (Tree) DFS

func (tree Tree) DFS(pre, post func(*TNode))

DFS traverses the tree using the Depth-First Search (DFS) algorithm.

[PARAMETERS]

pre func(*Node) // The preorder function which is called before accessing a root of any subtree.
post func(*Node) // The postorder function which is called after accessing a root of any subtree.

Jump to

Keyboard shortcuts

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