tree

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2020 License: GPL-3.0 Imports: 2 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VisitInOrder

func VisitInOrder(node *Node, call func(interface{}))

in-order visit of node

Types

type BST

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

func NewBST

func NewBST(orderFunc lib.OrderFunc) *BST

func (*BST) Insert

func (bst *BST) Insert(elem interface{}) *Node

func (*BST) Search

func (bst *BST) Search(elem interface{}) *Node

func (*BST) ToSlice

func (bst *BST) ToSlice() []interface{}

func (*BST) Traverse

func (bst *BST) Traverse(call func(interface{}))

type BSTInterface

type BSTInterface interface {
	// Adds new elem to the tree, will not check if same val already exists
	Insert(interface{}) *Node

	// Returns the first node that matches
	Search(interface{}) *Node

	// In-order traversal of tree copied to slice
	ToSlice() []interface{}

	// In-order traversal of tree, calling the func for each element visited
	Traverse(func(interface{}))
}

Binary Search Tree implementation https://en.wikipedia.org/wiki/Binary_search_tree Element comparison is based on OrderFunc provided to NewBST method

type Node

type Node struct {
	Left  *Node
	Right *Node
	Data  interface{}
}

func NewNode

func NewNode(data interface{}) *Node

Jump to

Keyboard shortcuts

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