binarysearchtree

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: MIT Imports: 1 Imported by: 1

Documentation

Overview

Package binarysearchtree provides functions to create/work with generic binary search trees.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinarySearchTree

type BinarySearchTree[T constraints.Ordered] struct {
	// contains filtered or unexported fields
}

BinarySearchTree is a binary search tree of an ordered type T.

func New

New creates a binary search tree of a constraints.Ordered type T.

func (*BinarySearchTree[T]) Find

func (bts *BinarySearchTree[T]) Find(v T) (n *Node[T], found bool)

Find returns the node of the binary search value that has a specific value.

func (*BinarySearchTree[T]) Height

func (bts *BinarySearchTree[T]) Height() int

Height returns the number of edges between the root of the tree and its deepest descendent, i.e. the height of the root.

func (*BinarySearchTree[T]) Insert

func (bts *BinarySearchTree[T]) Insert(v T)

Insert adds a value to the binary search tree.

func (*BinarySearchTree[T]) NodeDepth

func (bts *BinarySearchTree[T]) NodeDepth(n *Node[T]) int

NodeDepth returns the number of edges from the root of the tree to a node (the depth of a node).

func (*BinarySearchTree[T]) NodeHeight

func (bts *BinarySearchTree[T]) NodeHeight(n *Node[T]) int

NodeHeight returns the number of edges from a node to its deepest descendent (the height of a node).

func (*BinarySearchTree[T]) Remove

func (bts *BinarySearchTree[T]) Remove(n *Node[T])

Remove removes a node from the binary search tree.

func (*BinarySearchTree[T]) Root

func (bts *BinarySearchTree[T]) Root() *Node[T]

Root returns the root of the binary search tree.

func (*BinarySearchTree[T]) Size

func (bts *BinarySearchTree[T]) Size() int

Size returns the number of nodes in the binary search tree.

type Node

type Node[T comparable] struct {
	// contains filtered or unexported fields
}

Node is a node of a binary search tree.

func (*Node[T]) Left

func (n *Node[T]) Left() *Node[T]

Left returns the left child of the node.

func (*Node[T]) Parent

func (n *Node[T]) Parent() *Node[T]

Parent returns the parent of the node.

func (*Node[T]) Right

func (n *Node[T]) Right() *Node[T]

Right returns the right child of the node.

func (*Node[T]) Value

func (n *Node[T]) Value() T

Value returns the value of the node.

Jump to

Keyboard shortcuts

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