datastructure

package
v2.2.6 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package datastructure contains some data structure. BSTree is binary search tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BSTree

type BSTree[T any] struct {
	// contains filtered or unexported fields
}

BSTree is a binary search tree data structure in which each node has at most two children, which are referred to as the left child and the right child. In BSTree: leftNode < rootNode < rightNode type T should implements Compare function in lancetconstraints.Comparator interface.

func NewBSTree

func NewBSTree[T any](rootData T, comparator lancetconstraints.Comparator) *BSTree[T]

NewBSTree create a BSTree pointer param `comparator` is used to compare values in the tree

func (*BSTree[T]) Delete added in v2.0.8

func (t *BSTree[T]) Delete(data T)

DeletetNode delete data into BSTree

func (*BSTree[T]) Depth

func (t *BSTree[T]) Depth() int

Depth returns the calculated depth of a binary saerch tree

func (*BSTree[T]) HasSubTree added in v2.0.6

func (t *BSTree[T]) HasSubTree(subTree *BSTree[T]) bool

IsSubTree checks if the tree `t` has `subTree` or not

func (*BSTree[T]) InOrderTraverse

func (t *BSTree[T]) InOrderTraverse() []T

InOrderTraverse traverse tree node in mid order

func (*BSTree[T]) Insert added in v2.0.8

func (t *BSTree[T]) Insert(data T)

InsertNode insert data into BSTree

func (*BSTree[T]) LevelOrderTraverse

func (t *BSTree[T]) LevelOrderTraverse() []T

LevelOrderTraverse traverse tree node in level order

func (*BSTree[T]) NodeLevel

func (t *BSTree[T]) NodeLevel(node *datastructure.TreeNode[T]) int

NodeLevel get node level in BSTree

func (*BSTree[T]) PostOrderTraverse

func (t *BSTree[T]) PostOrderTraverse() []T

PostOrderTraverse traverse tree node in post order

func (*BSTree[T]) PreOrderTraverse

func (t *BSTree[T]) PreOrderTraverse() []T

PreOrderTraverse traverse tree node in pre order

func (*BSTree[T]) Print

func (t *BSTree[T]) Print()

Print the bstree structure

Jump to

Keyboard shortcuts

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