binarytree

package
v0.0.0-...-d12f04e Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyForDeletion = errors.New("Node child poistions is already empty")
View Source
var ErrNotEmptyForInsertion = errors.New("Node child poistions not empty for insertion")

Functions

This section is empty.

Types

type BinaryTree

type BinaryTree struct {
	Root *Node
}

func Init

func Init(payload interface{}) *BinaryTree

Init : Initializes a new binary tree with the given payload

func (*BinaryTree) Depth

func (tr *BinaryTree) Depth() int

Depth : Returns the depth of the tree

func (*BinaryTree) ToSliceInOrder

func (bt *BinaryTree) ToSliceInOrder() *[]Payload

ToSliceInOrder : Returns a slice of the tree in in-order traversal

func (*BinaryTree) ToSlicePostOrder

func (bt *BinaryTree) ToSlicePostOrder() *[]Payload

ToSlicePostOrder : Returns a slice of the tree in post order

func (*BinaryTree) ToSlicePreOrder

func (bt *BinaryTree) ToSlicePreOrder() *[]Payload

ToSlicePreOrder : Returns a slice of the tree in pre-order

type Node

type Node struct {
	Payload Payload
	// contains filtered or unexported fields
}

func (*Node) DeleteLeft

func (n *Node) DeleteLeft() (Payload, error)

DeleteLeft : Deletes the left child of the node

func (*Node) DeleteRight

func (n *Node) DeleteRight() (Payload, error)

DeleteRight : Deletes the right child of the node

func (*Node) Height

func (n *Node) Height() int

func (*Node) InsertLeft

func (n *Node) InsertLeft(payload Payload) (*Node, error)

InsertLeft : Inserts a node to the left of the current node

func (*Node) InsertRight

func (n *Node) InsertRight(payload Payload) (*Node, error)

InsertRight : Inserts a node to the right of the current node

type Payload

type Payload interface{}

Jump to

Keyboard shortcuts

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