package binary

import "git.sr.ht/~shulhan/pakakeh.go/lib/mining/tree/binary"

Package binary contain implementation of binary tree.

Index

Types

type BTNode

type BTNode struct {
	// Left branch of node.
	Left *BTNode
	// Right branch of node.
	Right *BTNode
	// Parent of node.
	Parent *BTNode
	// Value of node.
	Value any
}

BTNode is a data type for node in binary tree.

func NewBTNode

func NewBTNode(v any, l *BTNode, r *BTNode) (p *BTNode)

NewBTNode create new node for binary tree.

func (*BTNode) SetLeft

func (n *BTNode) SetLeft(c *BTNode)

SetLeft will set left branch of node to 'c'.

func (*BTNode) SetRight

func (n *BTNode) SetRight(c *BTNode)

SetRight will set right branch of node to 'c'.

func (*BTNode) String

func (n *BTNode) String() (s string)

String will convert the node to string.

type Tree

type Tree struct {
	// Root is pointer to root of tree.
	Root *BTNode
}

Tree is a abstract data type for tree with only two branch: left and right.

func NewTree

func NewTree() *Tree

NewTree will create new binary tree with empty root.

func (*Tree) String

func (btree *Tree) String() (s string)

String will print all the branch and leaf in tree.

Source Files

binary.go btnode.go

Version
v0.60.0 (latest)
Published
Feb 1, 2025
Platform
linux/amd64
Imports
2 packages
Last checked
9 hours ago

Tools for package owners.