binary

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2022 License: BSD-3-Clause, BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package binary contain implementation of binary tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 interface{}
}

BTNode is a data type for node in binary tree.

func NewBTNode

func NewBTNode(v interface{}, 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.

Jump to

Keyboard shortcuts

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