Tree

package
v0.0.0-...-f9b1802 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BSTreeNode

type BSTreeNode struct {
	Value int
	Left  *BSTreeNode
	Right *BSTreeNode
}

构建一个搜索二叉树

func (*BSTreeNode) Insert

func (n *BSTreeNode) Insert(value int)

func (*BSTreeNode) Search

func (n *BSTreeNode) Search(value int) *BSTreeNode

type GenericTree

type GenericTree[T Ordered] struct {
	// contains filtered or unexported fields
}

GenericTree 结构体存储树的根节点和树的大小

func NewBinarySearchTree

func NewBinarySearchTree[T Ordered]() *GenericTree[T]

NewBinarySearchTree 方法创建一个新的二叉树

func (*GenericTree[T]) Clear

func (b *GenericTree[T]) Clear()

Clear 方法清除树的元素并将大小设置为0

func (*GenericTree[T]) Contains

func (b *GenericTree[T]) Contains(val T) bool

Contains 方法返回一个布尔值,指示树中是否包含给定的元素

func (*GenericTree[T]) Delete

func (b *GenericTree[T]) Delete(val T)

Delete 方法从树中删除一个元素

func (*GenericTree[T]) Insert

func (b *GenericTree[T]) Insert(val T)

Insert 方法将一个元素插入到树中

func (*GenericTree[T]) IsEmpty

func (b *GenericTree[T]) IsEmpty() bool

IsEmpty 方法返回一个布尔值,指示树是否为空

func (*GenericTree[T]) Size

func (b *GenericTree[T]) Size() int

Size 方法返回树的大小

type Ordered

type Ordered interface {
	// Greater returns true if the receiver is greater than the other element.
	Greater(other Ordered) bool
	// Less returns true if the receiver is less than the other element.
	Less(other Ordered) bool
	// Equal returns true if the receiver is equal to the other element.
	Equal(other Ordered) bool
}

type TreeNode

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

TreeNode struct is used to store the elements of the tree

Jump to

Keyboard shortcuts

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