ds

package
v0.0.0-...-7e26a5e Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Array

func Array[T any](size int) *unsafeArray[T]

func DLRTree

func DLRTree(root *BTree)

前序遍历

func LDRTree

func LDRTree(root *BTree)

中序遍历

func LRDTree

func LRDTree(root *BTree)

后序遍历

func NewSafeSet

func NewSafeSet[T comparable]() *safeSet[T]

func NewSet

func NewSet[T comparable]() *unSafeSet[T]

func SafeArray

func SafeArray[T any](size int) *safeArray[T]

Types

type BTree

type BTree struct {
	Data  int
	Left  *BTree
	Right *BTree
}

type BinarySearchTree

type BinarySearchTree struct {
	Root *BinarySearchTreeNode
}

func NewBinarySearchTree

func NewBinarySearchTree() *BinarySearchTree

func (*BinarySearchTree) Add

func (tree *BinarySearchTree) Add(val int)

func (*BinarySearchTree) Delete

func (tree *BinarySearchTree) Delete(val int)

删除元素有四种情况: 第一种情况,删除的是根节点,且根节点没有儿子,直接删除即可。 第二种情况,删除的节点有父亲节点,但没有子树,也就是删除的是叶子节点,直接删除即可。 第三种情况,删除的节点下有两个子树,因为右子树的值都比左子树大,那么用右子树中的最小元素来替换删除的节点,这时二叉查找树的性质又满足了。右子树的最小元素,只要一直往右子树的左边一直找一直找就可以找到。 第四种情况,删除的节点只有一个子树,那么该子树直接替换被删除的节点即可。

func (*BinarySearchTree) FindMaxValue

func (tree *BinarySearchTree) FindMaxValue() *BinarySearchTreeNode

func (*BinarySearchTree) FindMinValue

func (tree *BinarySearchTree) FindMinValue() *BinarySearchTreeNode

func (*BinarySearchTree) FindOne

func (tree *BinarySearchTree) FindOne(val int) *BinarySearchTreeNode

func (*BinarySearchTree) FindParent

func (tree *BinarySearchTree) FindParent(val int) *BinarySearchTreeNode

type BinarySearchTreeNode

type BinarySearchTreeNode struct {
	Value int
	Times int
	Left  *BinarySearchTreeNode
	Right *BinarySearchTreeNode
}

func (*BinarySearchTreeNode) Add

func (node *BinarySearchTreeNode) Add(val int)

func (*BinarySearchTreeNode) FindMaxValue

func (node *BinarySearchTreeNode) FindMaxValue() *BinarySearchTreeNode

func (*BinarySearchTreeNode) FindMinValue

func (node *BinarySearchTreeNode) FindMinValue() *BinarySearchTreeNode

func (*BinarySearchTreeNode) FindOne

func (node *BinarySearchTreeNode) FindOne(val int) *BinarySearchTreeNode

func (*BinarySearchTreeNode) FindParent

func (node *BinarySearchTreeNode) FindParent(val int) *BinarySearchTreeNode

type FliterFunc

type FliterFunc[T any] func(item T) bool

过滤回调

type IArray

type IArray[T any] interface {
	Len() int
	IsEmpty() bool
	Add(val T) bool
	Concat(val ...[]T) []T
	Remove(fn FliterFunc[T]) bool
	Contain(fn FliterFunc[T]) bool
	Filter(fn FliterFunc[T]) []T
	Map(fn MapFunc[T]) []T
	List() []T
	Clear()
}

type ILinkedList

type ILinkedList[T any] interface {
	Len() int
	Add(val T) bool
	IsEmpty() bool
	Remove(fn FliterFunc[T]) bool
	Contain(fn FliterFunc[T]) bool
	First() ILinkedList[T]
	Last() ILinkedList[T]
	Clear()
}

type MapFunc

type MapFunc[T any] func(index int, item T) T

遍历回调

type Set

type Set[T comparable] interface {
	Len() int
	List() []T
	Add(val T) bool
	IsEmpty() bool
	Remove(val T) bool
	Contain(val T) bool
	Append(val ...T) int
	Clear()
}

Jump to

Keyboard shortcuts

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