tree

package
v0.0.0-...-1763559 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package tree :: tree.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BT

type BT interface {
	Left() BT
	Right() BT
	Value() interface{}
	SetLeft(BT)
	SetRight(BT)
	SetValue(interface{})
	Find(interface{}) BT
	Has(interface{}) bool
}

BT interface includes basic functions for a binary tree item

type BTNode

type BTNode struct {
	// contains filtered or unexported fields
}

BTNode represents a binary tree node

func NewBTNode

func NewBTNode(v interface{}, l, r BT) *BTNode

NewBTNode constructs an BTNode instance

func (*BTNode) Find

func (o *BTNode) Find(v interface{}) BT

Find returns the node matches to the value v

func (*BTNode) Has

func (o *BTNode) Has(v interface{}) bool

Has returns true if value v is found in any node; otherwise false

func (*BTNode) IsMirror

func (o *BTNode) IsMirror() bool

IsMirror checks if a binary tree is mirror of itself in recursive mode.

func (*BTNode) IsSymmetric

func (o *BTNode) IsSymmetric() bool

IsSymmetric checks if a binary tree is symmetric in interative mode.

func (*BTNode) Left

func (o *BTNode) Left() BT

Left implements BT

func (*BTNode) Right

func (o *BTNode) Right() BT

Right implements BT

func (*BTNode) SetLeft

func (o *BTNode) SetLeft(node BT)

SetLeft implements BT

func (*BTNode) SetRight

func (o *BTNode) SetRight(node BT)

SetRight implements BT

func (*BTNode) SetValue

func (o *BTNode) SetValue(v interface{})

SetValue implements BT

func (*BTNode) String

func (o *BTNode) String() string

String returns a string representation of StrBTNode object

func (*BTNode) Value

func (o *BTNode) Value() interface{}

Value implements BT

type IntBT

type IntBT interface {
	BT
	Sum() int
}

IntBT interface for any binary tree item contains int value

type IntBTNode

type IntBTNode struct {
	BTNode
}

IntBTNode represents an integer (int) binary tree node

func NewIntBTNode

func NewIntBTNode(v int, l, r IntBT) *IntBTNode

NewIntBTNode constructs an IntBTNode instance

func (*IntBTNode) Sum

func (it *IntBTNode) Sum() int

Sum adds up values in all tree nodes

type StrBT

type StrBT interface {
	BT
	Join(string) string
}

StrBT interface for any binary tree item contains string value

type StrBTNode

type StrBTNode struct {
	BTNode
}

StrBTNode represents an integer (int) binary tree node

func NewStrBTNode

func NewStrBTNode(v string, l, r StrBT) *StrBTNode

NewStrBTNode constructs an StrBTNode instance

func (*StrBTNode) Join

func (it *StrBTNode) Join(sep string) string

Join concatenates values in all tree nodes

Jump to

Keyboard shortcuts

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