Documentation
¶
Overview ¶
Package AVLTree functions
Example (AvlTree) ¶
package main import ( "fmt" "github.com/jenazads/gods/trees/avltree" "github.com/jenazads/goutils" ) func main() { tree := avltree.NewAVLTree(goutils.IntComparator, goutils.IntOperator) tree.Insert(1, "x") tree.Insert(2, "b") tree.Insert(1, "a") tree.Insert(3, "c") tree.Insert(4, "d") tree.Insert(5, "e") 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(6) fmt.Println(tree) tree.Remove(1) fmt.Println(tree) tree.Remove(4) fmt.Println(tree) tree.Remove(8) fmt.Println(tree) tree.Clear() tree.IsEmpty() tree.Size() }
Output:
Index ¶
- func IsLeaf(node *AVLNode) bool
- type AVLNode
- type AVLTree
- func (t *AVLTree) Brother(key interface{}) *AVLNode
- func (t *AVLTree) Ceiling(key interface{}) *AVLNode
- func (t *AVLTree) Clear()
- func (t *AVLTree) Floor(key interface{}) *AVLNode
- func (t *AVLTree) FromJSON(data []byte) error
- func (t *AVLTree) Get(key interface{}) interface{}
- func (t *AVLTree) Height() int
- func (t *AVLTree) HeightOfNode(key interface{}) int
- func (t *AVLTree) Insert(key interface{}, value interface{})
- func (t *AVLTree) IsEmpty() bool
- func (t *AVLTree) IsSameAs(otherTree *AVLTree) bool
- func (t *AVLTree) Iterator() goutils.ReverseIteratorKey
- func (t *AVLTree) Keys() []interface{}
- func (t *AVLTree) LeafCount() int
- func (t *AVLTree) Left() *AVLNode
- func (t *AVLTree) Mirror()
- func (t *AVLTree) Parent(key interface{}) *AVLNode
- func (t *AVLTree) Print()
- func (t *AVLTree) PrintInOrder()
- func (t *AVLTree) PrintPostOrder()
- func (t *AVLTree) PrintPreOrder()
- func (t *AVLTree) Remove(key interface{})
- func (t *AVLTree) Right() *AVLNode
- func (t *AVLTree) Search(key interface{}) *AVLNode
- func (t *AVLTree) Size() int
- func (t *AVLTree) String() string
- func (t *AVLTree) SumNodes() interface{}
- func (t *AVLTree) ToJSON() ([]byte, error)
- func (t *AVLTree) 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 AVLNode ¶
type AVLNode struct { Key interface{} Value interface{} Parent *AVLNode // Parent node Children [2]*AVLNode // Children nodes, 0-> left, 1-> right // contains filtered or unexported fields }
Node
func NewAVLNode ¶
New AVL Node
type AVLTree ¶
type AVLTree struct { Root *AVLNode // Root node // contains filtered or unexported fields }
AVLTree object
func NewAVLTree ¶
func NewAVLTree(comp goutils.TypeComparator, op goutils.TypeOperator) *AVLTree
New AVL Tree
func (*AVLTree) HeightOfNode ¶
Return the height of a specific node
func (*AVLTree) Insert ¶
func (t *AVLTree) Insert(key interface{}, value interface{})
Insert New Node by Key
func (*AVLTree) Iterator ¶
func (t *AVLTree) Iterator() goutils.ReverseIteratorKey
Iterator returns a stateful iterator whose elements are key/value pairs.
Click to show internal directories.
Click to hide internal directories.