Documentation ¶
Overview ¶
Package datastructure contains some data structure. BSTree is binary search tree.
Index ¶
- type BSTree
- func (t *BSTree[T]) Delete(data T)
- func (t *BSTree[T]) Depth() int
- func (t *BSTree[T]) HasSubTree(subTree *BSTree[T]) bool
- func (t *BSTree[T]) InOrderTraverse() []T
- func (t *BSTree[T]) Insert(data T)
- func (t *BSTree[T]) LevelOrderTraverse() []T
- func (t *BSTree[T]) NodeLevel(node *datastructure.TreeNode[T]) int
- func (t *BSTree[T]) PostOrderTraverse() []T
- func (t *BSTree[T]) PreOrderTraverse() []T
- func (t *BSTree[T]) Print()
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]) HasSubTree ¶ added in v2.0.6
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