Documentation ¶
Overview ¶
Package Binary Search Tree functions
Example (BsTree) ¶
package main import ( "fmt" "github.com/jenazads/gods/trees/bstree" "github.com/jenazads/goutils" ) func main() { tree := bstree.NewBSTree(goutils.IntComparator, goutils.IntOperator) tree.Insert(5, "e") tree.Insert(2, "b") tree.Insert(3, "c") tree.Insert(1, "a") tree.Insert(4, "d") tree.Insert(6, "f") tree.Insert(7, "g") tree.Insert(8, "h") tree.PrintPreOrder() tree.PrintInOrder() tree.PrintPostOrder() fmt.Println(tree.Ceiling(4)) fmt.Println(tree.Floor(5)) tree.Print() fmt.Println(tree.Values()) fmt.Println(tree.Keys()) fmt.Print(tree) tree.Remove(3) fmt.Println(tree) tree.Remove(2) fmt.Println(tree) tree.Remove(7) fmt.Println(tree) tree.Remove(5) fmt.Println(tree) tree.Remove(4) fmt.Println(tree) tree.Remove(1) fmt.Println(tree) tree.Remove(6) fmt.Println(tree) tree.Remove(8) fmt.Println(tree) tree.Clear() tree.IsEmpty() tree.Size() }
Output:
Index ¶
- func IsLeaf(node *BSTNode) bool
- type BSTNode
- type BSTree
- func (t *BSTree) Brother(key interface{}) *BSTNode
- func (t *BSTree) Ceiling(key interface{}) *BSTNode
- func (t *BSTree) Clear()
- func (t *BSTree) Floor(key interface{}) *BSTNode
- func (t *BSTree) FromJSON(data []byte) error
- func (t *BSTree) Get(key interface{}) interface{}
- func (t *BSTree) Height() int
- func (t *BSTree) HeightOfNode(key interface{}) int
- func (t *BSTree) Insert(key interface{}, value interface{})
- func (t *BSTree) IsEmpty() bool
- func (t *BSTree) IsSameAs(otherTree *BSTree) bool
- func (t *BSTree) Iterator() goutils.ReverseIteratorKey
- func (t *BSTree) Keys() []interface{}
- func (t *BSTree) LeafCount() int
- func (t *BSTree) Left() *BSTNode
- func (t *BSTree) Mirror()
- func (t *BSTree) Parent(key interface{}) *BSTNode
- func (t *BSTree) Print()
- func (t *BSTree) PrintInOrder()
- func (t *BSTree) PrintPostOrder()
- func (t *BSTree) PrintPreOrder()
- func (t *BSTree) Remove(key interface{})
- func (t *BSTree) Right() *BSTNode
- func (t *BSTree) Search(key interface{}) *BSTNode
- func (t *BSTree) Size() int
- func (t *BSTree) String() string
- func (t *BSTree) SumNodes() interface{}
- func (t *BSTree) ToJSON() ([]byte, error)
- func (t *BSTree) Values() []interface{}
- type Iterator
- func (iterator *Iterator) Begin()
- func (iterator *Iterator) End()
- func (iterator *Iterator) First() bool
- func (iterator *Iterator) Key() interface{}
- func (iterator *Iterator) Last() bool
- func (iterator *Iterator) Next() bool
- func (iterator *Iterator) Prev() bool
- func (iterator *Iterator) Value() interface{}
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BSTNode ¶
type BSTNode struct { Key interface{} Value []interface{} Count int Parent *BSTNode // Parent node Children [2]*BSTNode // Children nodes, 0-> left, 1-> right }
Node
type BSTree ¶
type BSTree struct { Root *BSTNode // Root node // contains filtered or unexported fields }
BSTree object
func NewBSTree ¶
func NewBSTree(comp goutils.TypeComparator, op goutils.TypeOperator) *BSTree
New BS Tree
func (*BSTree) HeightOfNode ¶
Return the height of a specific node
func (*BSTree) Insert ¶
func (t *BSTree) Insert(key interface{}, value interface{})
Insert New Node by Key
func (*BSTree) Iterator ¶
func (t *BSTree) Iterator() goutils.ReverseIteratorKey
Iterator returns a stateful iterator whose elements are key/value pairs.
Click to show internal directories.
Click to hide internal directories.