binary

package
v0.0.0-...-38a5715 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Package binary is an implementation of a balanced binary tree. A majority of this code comes from appliedgo. https://appliedgo.net/balancedtree/ https://appliedgo.net/bintree/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrettyPrint

func PrettyPrint(t Tree)

PrettyPrint takes a Tree value and displays a pretty print version of the tree.

Types

type Data

type Data struct {
	Key  int
	Name string
}

Data represents the information being stored.

type Tree

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

Tree represents all values in the tree.

func (*Tree) Delete

func (t *Tree) Delete(key int) error

Delete removes the key from the tree and keeps it balaned.

func (*Tree) Find

func (t *Tree) Find(key int) (Data, error)

Find traverses the tree looking for the specified tree.

func (*Tree) InOrder

func (t *Tree) InOrder() []Data

InOrder traversal travel from the leftmost node to the rightmost nodes regardless of depth. In-order traversal gives node values in ascending order.

      #4
   /      \
  #2      #6
 /  \    /  \
#1  #3  #5  #7

func (*Tree) Insert

func (t *Tree) Insert(data Data)

Insert adds a value into the tree and keeps the tree balanced.

func (*Tree) PostOrder

func (t *Tree) PostOrder() []Data

PostOrder traversal get the leftmost node then its sibling then go up to its parent, recursively. Use cases: tree deletion, mapping postfix notation.

      #7
   /      \
  #3      #6
 /  \    /  \
#1  #2  #4  #5

func (*Tree) PreOrder

func (t *Tree) PreOrder() []Data

PreOrder traversal get the root node then traversing its child nodes recursively. Use cases: copying tree, mapping prefix notation.

      #1
   /      \
  #2      #5
 /  \    /  \
#3  #4  #6  #7

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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