binarysearchtree

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package binarysearchtree provides interface and implementations for binary search tree data structure

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinarySearchTree

type BinarySearchTree[T cmp.Ordered] struct {
	Root *BinaryTreeNode[T]
}

BinarySearchTree contains a pointer to the root node.

func NewBinarySearchTree

func NewBinarySearchTree[T cmp.Ordered](values ...T) *BinarySearchTree[T]

NewBinarySearchTree instantiates a binary search tree and returns a pointer to it.

func (*BinarySearchTree[T]) Contains

func (b *BinarySearchTree[T]) Contains(i T) bool

Contains returns true if the given item is in the binary search tree.

func (*BinarySearchTree[T]) Insert

func (b *BinarySearchTree[T]) Insert(i T) bool

Insert inserts the given item into the binary search tree. It returns a Boolean that is true if the item was not already in the binary search tree.

func (*BinarySearchTree[T]) Remove

func (b *BinarySearchTree[T]) Remove(i T) bool

Remove removes the given item from the binary search tree. It returns a Boolean that is true if the item was in the binary search tree.

type BinaryTreeNode

type BinaryTreeNode[T cmp.Ordered] struct {
	Val   T
	Left  *BinaryTreeNode[T]
	Right *BinaryTreeNode[T]
}

BinaryTreeNode contains a value, a pointer to the left child node, and a pointer to the right child node.

func NewBinaryTreeNode

func NewBinaryTreeNode[T cmp.Ordered](i T) *BinaryTreeNode[T]

Jump to

Keyboard shortcuts

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