Documentation
¶
Index ¶
- Constants
- func PrintBinaryTree[T CmpT](node *BinaryTreeNode[T], cb func(node *BinaryTreeNode[T]) string)
- type BinaryTree
- func (t *BinaryTree[T]) Add(ele T)
- func (t *BinaryTree[T]) FindNode(ele T) (*BinaryTreeNode[T], bool)
- func (t *BinaryTree[T]) FindSuccessor(node *BinaryTreeNode[T]) *BinaryTreeNode[T]
- func (t *BinaryTree[T]) Height() int
- func (t *BinaryTree[T]) InOrder(cb func(node *BinaryTreeNode[T]))
- func (t *BinaryTree[T]) InOrderByVisitor(cb func(node *BinaryTreeNode[T]))
- func (t *BinaryTree[T]) Len() int
- func (t *BinaryTree[T]) LevelOrder(cb func(node *BinaryTreeNode[T]))
- func (t *BinaryTree[T]) LevelOrderByVisitor(cb func(node *BinaryTreeNode[T]))
- func (t *BinaryTree[T]) PostOrder(cb func(node *BinaryTreeNode[T]))
- func (t *BinaryTree[T]) PostOrderByVisitor(cb func(node *BinaryTreeNode[T]))
- func (t *BinaryTree[T]) PreOrder(cb func(node *BinaryTreeNode[T]))
- func (t *BinaryTree[T]) PreOrderByVisitor(cb func(node *BinaryTreeNode[T]))
- func (t *BinaryTree[T]) Predecessor(node *BinaryTreeNode[T]) *BinaryTreeNode[T]
- func (t *BinaryTree[T]) Remove(ele T)
- type BinaryTreeNode
- func (n *BinaryTreeNode[T]) ColorBlack()
- func (n *BinaryTreeNode[T]) ColorRed()
- func (n *BinaryTreeNode[T]) GetElement() interface{}
- func (n *BinaryTreeNode[T]) HasTwoChildren() bool
- func (n *BinaryTreeNode[T]) Height() int
- func (n *BinaryTreeNode[T]) IsAvlBalance() bool
- func (n *BinaryTreeNode[T]) IsBlack() bool
- func (n *BinaryTreeNode[T]) IsLeaf() bool
- func (n *BinaryTreeNode[T]) IsLeftChild() bool
- func (n *BinaryTreeNode[T]) IsRed() bool
- func (n *BinaryTreeNode[T]) IsRightChild() bool
- func (n *BinaryTreeNode[T]) LeftHeight() int
- func (n *BinaryTreeNode[T]) RightHeight() int
- func (n *BinaryTreeNode[T]) UpdateHeight()
- type CmpT
- type SimpleQueue
Constants ¶
View Source
const ( BinarySearchTreeType = iota AvlTreeType RbTreeType )
Variables ¶
This section is empty.
Functions ¶
func PrintBinaryTree ¶
func PrintBinaryTree[T CmpT](node *BinaryTreeNode[T], cb func(node *BinaryTreeNode[T]) string)
//树状字符 //"└" "─" "┌─────────┴─────────┐" "┬" //"├" //"─┴─"
Types ¶
type BinaryTree ¶
type BinaryTree[T CmpT] struct { Root *BinaryTreeNode[T] TreeType int // contains filtered or unexported fields }
二叉树
func NewBinaryTree ¶
func NewBinaryTree[T CmpT]() *BinaryTree[T]
func NewRbTree ¶
func NewRbTree[T CmpT]() *BinaryTree[T]
func (*BinaryTree[T]) Add ¶
func (t *BinaryTree[T]) Add(ele T)
func (*BinaryTree[T]) FindNode ¶
func (t *BinaryTree[T]) FindNode(ele T) (*BinaryTreeNode[T], bool)
根据元素找到节点
func (*BinaryTree[T]) FindSuccessor ¶
func (t *BinaryTree[T]) FindSuccessor(node *BinaryTreeNode[T]) *BinaryTreeNode[T]
找后继者
func (*BinaryTree[T]) InOrder ¶
func (t *BinaryTree[T]) InOrder(cb func(node *BinaryTreeNode[T]))
func (*BinaryTree[T]) InOrderByVisitor ¶
func (t *BinaryTree[T]) InOrderByVisitor(cb func(node *BinaryTreeNode[T]))
func (*BinaryTree[T]) Len ¶
func (t *BinaryTree[T]) Len() int
func (*BinaryTree[T]) LevelOrder ¶
func (t *BinaryTree[T]) LevelOrder(cb func(node *BinaryTreeNode[T]))
func (*BinaryTree[T]) LevelOrderByVisitor ¶
func (t *BinaryTree[T]) LevelOrderByVisitor(cb func(node *BinaryTreeNode[T]))
func (*BinaryTree[T]) PostOrder ¶
func (t *BinaryTree[T]) PostOrder(cb func(node *BinaryTreeNode[T]))
func (*BinaryTree[T]) PostOrderByVisitor ¶
func (t *BinaryTree[T]) PostOrderByVisitor(cb func(node *BinaryTreeNode[T]))
func (*BinaryTree[T]) PreOrder ¶
func (t *BinaryTree[T]) PreOrder(cb func(node *BinaryTreeNode[T]))
func (*BinaryTree[T]) PreOrderByVisitor ¶
func (t *BinaryTree[T]) PreOrderByVisitor(cb func(node *BinaryTreeNode[T]))
func (*BinaryTree[T]) Predecessor ¶
func (t *BinaryTree[T]) Predecessor(node *BinaryTreeNode[T]) *BinaryTreeNode[T]
找前驱
func (*BinaryTree[T]) Remove ¶
func (t *BinaryTree[T]) Remove(ele T)
type BinaryTreeNode ¶
type BinaryTreeNode[T CmpT] struct { Index int //在二叉树中索引,打印辅助 // contains filtered or unexported fields }
func NewBinaryTreeNode ¶
func NewBinaryTreeNode[T CmpT](element T, parent *BinaryTreeNode[T]) *BinaryTreeNode[T]
func RotateLeft ¶
func RotateLeft[T CmpT](node *BinaryTreeNode[T]) *BinaryTreeNode[T]
func RotateRight ¶
func RotateRight[T CmpT](node *BinaryTreeNode[T]) *BinaryTreeNode[T]
func (*BinaryTreeNode[T]) ColorBlack ¶
func (n *BinaryTreeNode[T]) ColorBlack()
func (*BinaryTreeNode[T]) ColorRed ¶
func (n *BinaryTreeNode[T]) ColorRed()
func (*BinaryTreeNode[T]) GetElement ¶
func (n *BinaryTreeNode[T]) GetElement() interface{}
func (*BinaryTreeNode[T]) HasTwoChildren ¶
func (n *BinaryTreeNode[T]) HasTwoChildren() bool
是否有2个孩子
func (*BinaryTreeNode[T]) Height ¶
func (n *BinaryTreeNode[T]) Height() int
func (*BinaryTreeNode[T]) IsBlack ¶
func (n *BinaryTreeNode[T]) IsBlack() bool
func (*BinaryTreeNode[T]) IsLeaf ¶
func (n *BinaryTreeNode[T]) IsLeaf() bool
func (*BinaryTreeNode[T]) IsLeftChild ¶
func (n *BinaryTreeNode[T]) IsLeftChild() bool
func (*BinaryTreeNode[T]) IsRed ¶
func (n *BinaryTreeNode[T]) IsRed() bool
func (*BinaryTreeNode[T]) IsRightChild ¶
func (n *BinaryTreeNode[T]) IsRightChild() bool
func (*BinaryTreeNode[T]) LeftHeight ¶
func (n *BinaryTreeNode[T]) LeftHeight() int
func (*BinaryTreeNode[T]) RightHeight ¶
func (n *BinaryTreeNode[T]) RightHeight() int
func (*BinaryTreeNode[T]) UpdateHeight ¶
func (n *BinaryTreeNode[T]) UpdateHeight()
type SimpleQueue ¶
type SimpleQueue struct {
// contains filtered or unexported fields
}
func NewSimpleQueue ¶
func NewSimpleQueue() *SimpleQueue
func (*SimpleQueue) Empty ¶
func (q *SimpleQueue) Empty() bool
func (*SimpleQueue) Len ¶
func (q *SimpleQueue) Len() int
func (*SimpleQueue) Offer ¶
func (q *SimpleQueue) Offer(ele interface{})
func (*SimpleQueue) Poll ¶
func (q *SimpleQueue) Poll() (ele interface{})
Click to show internal directories.
Click to hide internal directories.