gotype

package module
v0.0.0-...-6aa1591 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2020 License: Apache-2.0 Imports: 2 Imported by: 16

README

gotype

golang base type extend

用于演示算法的一些数据结构

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(x int) int

func CreateNode

func CreateNode(node *LNode, max int)

创建链表

func IsNumber

func IsNumber(c rune) bool

func IsOne

func IsOne(n, i int) bool

判断数字n的二进制数从右往左数第i位是否为1

func Max

func Max(a, b int) int

func Max3

func Max3(a, b, c int) int

func Min

func Min(a, b int) int

func Min3

func Min3(a, b, c int) int

func PrintNode

func PrintNode(info string, node *LNode)

打印链表的方法

func PrintTreeLayer

func PrintTreeLayer(node *BNode)

层序打印二叉树

func PrintTreeMidOrder

func PrintTreeMidOrder(root *BNode)

用中序遍历的方式打印出二叉树结点的内容

func SwapInt

func SwapInt(data []int, x, y int)

func SwapRune

func SwapRune(data []rune, x, y int)

Types

type AVLNode

type AVLNode struct {
	Data   int
	Height int
	Count  int
	Left   *AVLNode
	Right  *AVLNode
}

AVL树

func NewAVLNode

func NewAVLNode(data int) *AVLNode

type BNode

type BNode struct {
	Data       interface{}
	LeftChild  *BNode
	RightChild *BNode
}

二叉树定义

func ArrayToTree

func ArrayToTree(arr []int, start int, end int) *BNode

通过数组创建中序的二叉树

func NewBNode

func NewBNode() *BNode

type LNode

type LNode struct {
	Data interface{}
	Next *LNode
}

链表定义

func NewLNode

func NewLNode() *LNode

type LinkedQueue

type LinkedQueue struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewLinkedQueue

func NewLinkedQueue() *LinkedQueue

func (*LinkedQueue) DeQueue

func (p *LinkedQueue) DeQueue() interface{}

出队列,删除队列首元素

func (*LinkedQueue) EnQueue

func (p *LinkedQueue) EnQueue(e interface{})

入队列:把元素e加到队列尾

func (*LinkedQueue) GetBack

func (p *LinkedQueue) GetBack() interface{}

取得队列尾元素

func (*LinkedQueue) GetFront

func (p *LinkedQueue) GetFront() interface{}

取得队列首元素

func (*LinkedQueue) IsEmpty

func (p *LinkedQueue) IsEmpty() bool

判断队列是否为空,如果为空返回true,否则返回false

func (*LinkedQueue) Size

func (p *LinkedQueue) Size() int

获取栈中元素的个数

type LinkedStack

type LinkedStack struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

链表所写的stack

func NewLinkedStack

func NewLinkedStack() *LinkedStack

func (*LinkedStack) IsEmpty

func (p *LinkedStack) IsEmpty() bool

func (*LinkedStack) Pop

func (p *LinkedStack) Pop() interface{}

func (*LinkedStack) Push

func (p *LinkedStack) Push(e interface{})

func (*LinkedStack) Size

func (p *LinkedStack) Size() int

func (*LinkedStack) Top

func (p *LinkedStack) Top() interface{}

type Set

type Set struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSet

func NewSet() *Set

func (*Set) Add

func (s *Set) Add(item interface{})

func (*Set) Clear

func (s *Set) Clear()

func (*Set) Contains

func (s *Set) Contains(item interface{}) bool

func (*Set) IsEmpty

func (s *Set) IsEmpty() bool

func (*Set) Len

func (s *Set) Len() int

func (*Set) List

func (s *Set) List() []interface{}

func (*Set) Remove

func (s *Set) Remove(item interface{})

type SliceQueue

type SliceQueue struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSliceQueue

func NewSliceQueue() *SliceQueue

func (*SliceQueue) DeQueue

func (p *SliceQueue) DeQueue() interface{}

删除队列头元素

func (*SliceQueue) EnQueue

func (p *SliceQueue) EnQueue(item interface{})

把新元素加入队列尾

func (*SliceQueue) EnQueueFirst

func (p *SliceQueue) EnQueueFirst(item interface{})

把新元素加入队列首

func (*SliceQueue) GetBack

func (p *SliceQueue) GetBack() interface{}

返回队列尾元素

func (*SliceQueue) GetFront

func (p *SliceQueue) GetFront() interface{}

返回队列首元素

func (*SliceQueue) IsEmpty

func (p *SliceQueue) IsEmpty() bool

判断队列是否为空

func (*SliceQueue) List

func (p *SliceQueue) List() []interface{}

func (*SliceQueue) PopBack

func (p *SliceQueue) PopBack() interface{}

返回并移除队列尾元素

func (*SliceQueue) Remove

func (p *SliceQueue) Remove(item interface{})

简单实现一个Remove

func (*SliceQueue) Size

func (p *SliceQueue) Size() int

返回队列的大小

type SliceStack

type SliceStack struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

slice所写的stack

func NewSliceStack

func NewSliceStack() *SliceStack

func (*SliceStack) IsEmpty

func (p *SliceStack) IsEmpty() bool

判断是否为空

func (*SliceStack) List

func (p *SliceStack) List() []interface{}

func (*SliceStack) Pop

func (p *SliceStack) Pop() interface{}

弹出栈元素

func (*SliceStack) Push

func (p *SliceStack) Push(t interface{})

Push栈元素

func (*SliceStack) Size

func (p *SliceStack) Size() int

返回大小

func (*SliceStack) Top

func (p *SliceStack) Top() interface{}

返回栈顶元素

type TrieNode

type TrieNode struct {
	IsLeaf bool
	Url    string
	Child  []*TrieNode
}

Trie树

func NewTrieNode

func NewTrieNode(count int) *TrieNode

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL