Documentation
¶
Overview ¶
This package implements binary search tree
Example ¶
package main
import (
"fmt"
"github.com/dungtl2003/data-structure/bst"
)
func main() {
tree := bst.New[int]()
tree.Add(40)
tree.Add(30)
tree.Add(25)
tree.Add(35)
tree.Add(50)
tree.Add(45)
tree.Add(60)
tree.Add(40)
fmt.Printf("%v\n", tree.InOrder())
fmt.Printf("There are %d number %d\n", tree.Root().Occurs, tree.Root().Val)
}
Output: [25 30 35 40 45 50 60] There are 2 number 40
Index ¶
- type BST
- func (bst *BST[T]) Add(data T)
- func (bst *BST[T]) Contains(data T) bool
- func (bst *BST[T]) InOrder() []T
- func (bst *BST[T]) Init() *BST[T]
- func (bst *BST[T]) PostOrder() []T
- func (bst *BST[T]) PreOrder() []T
- func (bst *BST[T]) Remove(data T, ignoreOccurs bool)
- func (bst *BST[T]) Root() *Node[T]
- func (bst *BST[T]) Size() uint
- type Node
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BST ¶
Binary search tree data structure, useful for searching data
func (*BST[T]) Add ¶
func (bst *BST[T]) Add(data T)
Add a new node with `data` to the binary search tree IF the `data` does not exist in the tree, else it will only increase the occurrences of the `data`
Click to show internal directories.
Click to hide internal directories.