Documentation ¶
Overview ¶
For more details check out those links below here: Wikipedia article: https://en.wikipedia.org/wiki/Binary_search_tree authors [guuzaa](https://github.com/guuzaa)
Index ¶
- type AVL
- func (t AVL) AccessNodesByLayer() [][]T
- func (avl *AVL[T]) Delete(key T) bool
- func (t AVL) Depth() int
- func (t AVL) Get(key T) (*Node[T], bool)
- func (t AVL) Has(key T) bool
- func (t AVL) InOrder() []T
- func (t AVL) LevelOrder() []T
- func (t AVL) Max() (T, bool)
- func (t AVL) Min() (T, bool)
- func (t AVL) PostOrder() []T
- func (t AVL) PreOrder() []T
- func (t AVL) Print()
- func (avl *AVL[T]) Push(keys ...T)
- type BinarySearch
- func (t BinarySearch) AccessNodesByLayer() [][]T
- func (t *BinarySearch[T]) Delete(val T) bool
- func (t BinarySearch) Depth() int
- func (t BinarySearch) Get(key T) (*Node[T], bool)
- func (t BinarySearch) Has(key T) bool
- func (t BinarySearch) InOrder() []T
- func (t BinarySearch) LevelOrder() []T
- func (t BinarySearch) Max() (T, bool)
- func (t BinarySearch) Min() (T, bool)
- func (t BinarySearch) PostOrder() []T
- func (t BinarySearch) PreOrder() []T
- func (t BinarySearch) Print()
- func (t *BinarySearch[T]) Push(keys ...T)
- type Color
- type Node
- type RB
- func (t RB) AccessNodesByLayer() [][]T
- func (t *RB[T]) Delete(data T) bool
- func (t RB) Depth() int
- func (t RB) Get(key T) (*Node[T], bool)
- func (t RB) Has(key T) bool
- func (t RB) InOrder() []T
- func (t RB) LevelOrder() []T
- func (t RB) Max() (T, bool)
- func (t RB) Min() (T, bool)
- func (t RB) PostOrder() []T
- func (t RB) PreOrder() []T
- func (t *RB[T]) Predecessor(key T) (T, bool)
- func (t RB) Print()
- func (t *RB[T]) Push(keys ...T)
- func (t *RB[T]) Successor(key T) (T, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AVL ¶
type AVL[T constraints.Ordered] struct { // contains filtered or unexported fields }
func (AVL) AccessNodesByLayer ¶
func (t AVL) AccessNodesByLayer() [][]T
AccessNodesByLayer accesses nodes layer by layer (2-D array), instead of printing the results as 1-D array.
func (AVL) Depth ¶
func (t AVL) Depth() int
Depth returns the calculated depth of a binary search tree
func (AVL) InOrder ¶
func (t AVL) InOrder() []T
Traverses the tree in the following order Left --> Root --> Right
func (AVL) LevelOrder ¶
func (t AVL) LevelOrder() []T
LevelOrder returns the level order traversal of the tree
func (AVL) PostOrder ¶
func (t AVL) PostOrder() []T
Traverses the tree in the following order Left --> Right --> Root
type BinarySearch ¶
type BinarySearch[T constraints.Ordered] struct { // contains filtered or unexported fields }
func NewBinarySearch ¶
func NewBinarySearch[T constraints.Ordered]() *BinarySearch[T]
NewBinarySearch create a novel Binary-Search tree
func (BinarySearch) AccessNodesByLayer ¶
func (t BinarySearch) AccessNodesByLayer() [][]T
AccessNodesByLayer accesses nodes layer by layer (2-D array), instead of printing the results as 1-D array.
func (*BinarySearch[T]) Delete ¶
func (t *BinarySearch[T]) Delete(val T) bool
Delete removes the node of val
func (BinarySearch) Depth ¶
func (t BinarySearch) Depth() int
Depth returns the calculated depth of a binary search tree
func (BinarySearch) Has ¶
func (t BinarySearch) Has(key T) bool
Determines the tree has the node of Key
func (BinarySearch) InOrder ¶
func (t BinarySearch) InOrder() []T
Traverses the tree in the following order Left --> Root --> Right
func (BinarySearch) LevelOrder ¶
func (t BinarySearch) LevelOrder() []T
LevelOrder returns the level order traversal of the tree
func (BinarySearch) PostOrder ¶
func (t BinarySearch) PostOrder() []T
Traverses the tree in the following order Left --> Right --> Root
func (BinarySearch) PreOrder ¶
func (t BinarySearch) PreOrder() []T
Traverses the tree in the following order Root --> Left --> Right
func (*BinarySearch[T]) Push ¶
func (t *BinarySearch[T]) Push(keys ...T)
Push a chain of Node's into the BinarySearch
type Node ¶
type Node[T constraints.Ordered] struct { Key T Parent *Node[T] // for Red-Black Tree Left *Node[T] Right *Node[T] Color Color // for Red-Black Tree Height int // for AVL Tree }
Node of a binary tree
type RB ¶
type RB[T constraints.Ordered] struct { // contains filtered or unexported fields }
func (RB) AccessNodesByLayer ¶
func (t RB) AccessNodesByLayer() [][]T
AccessNodesByLayer accesses nodes layer by layer (2-D array), instead of printing the results as 1-D array.
func (*RB[T]) Delete ¶
Delete a node of Red-Black Tree Returns false if the node does not exist, otherwise returns true.
func (RB) Depth ¶
func (t RB) Depth() int
Depth returns the calculated depth of a binary search tree
func (RB) InOrder ¶
func (t RB) InOrder() []T
Traverses the tree in the following order Left --> Root --> Right
func (RB) LevelOrder ¶
func (t RB) LevelOrder() []T
LevelOrder returns the level order traversal of the tree
func (RB) PostOrder ¶
func (t RB) PostOrder() []T
Traverses the tree in the following order Left --> Right --> Root
func (RB) PreOrder ¶
func (t RB) PreOrder() []T
Traverses the tree in the following order Root --> Left --> Right
func (*RB[T]) Predecessor ¶
Return the Predecessor of the node of Key if there is no predecessor, return default value of type T and false otherwise return the Key of predecessor and true