structure

package
v0.0.0-...-6d07767 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Node2Array

func Node2Array(node *ListNode) []any

node 结点转数组

@param node
@return []any

Types

type BinarySearchTree

type BinarySearchTree struct {
	Root *TreeNode
}

二叉搜索树结构,里面保存一个根节点

func (*BinarySearchTree) Delete

func (t *BinarySearchTree) Delete(key int)

func (*BinarySearchTree) InOrderTraversal

func (t *BinarySearchTree) InOrderTraversal() []int

中序遍历

func (*BinarySearchTree) Insert

func (t *BinarySearchTree) Insert(data int)

插入操作

func (*BinarySearchTree) Inserts

func (t *BinarySearchTree) Inserts(args ...int)

批量插入

func (*BinarySearchTree) Search

func (t *BinarySearchTree) Search(data int) *TreeNode

查找操作

type BinarySearchTreeInterface

type BinarySearchTreeInterface interface {
	// 插入操作
	// @param int 要插入的数据
	Insert(int)

	// 插入操作,支持批量插入
	Inserts(...int)

	// 查询操作
	// @param int 要查询的数据
	Search(int) *TreeNode

	// 中序遍历,输出有序序列
	InOrderTraversal() []int

	// 删除操作
	// @param int 要删除的数据
	Delete(int)
}

接口定义

type LinkedList

type LinkedList struct {
	Head   *ListNode // 头结点,一般数据域为空或存放链表的长度
	Length int       // 链表长度
}

单链表数据结构

func Array2List

func Array2List(arr []any) *LinkedList

数组转链表

@param arr

func NewLinkedList

func NewLinkedList() *LinkedList

模拟构造函数,构造一个单链表

@return *LinkedList

func (*LinkedList) ToArray

func (l *LinkedList) ToArray() []any

链表转数组: 使用递归 + 闭包

@receiver linkList
@return []any

type ListNode

type ListNode struct {
	Data any
	Next *ListNode
}

type SqQueue

type SqQueue []any

顺序队列实现:数组本身就可以看做是一个顺序队列

func NewSqQueue

func NewSqQueue(capacity int) SqQueue

func (SqQueue) DeQueue

func (q SqQueue) DeQueue() (SqQueue, any)

func (SqQueue) EnQueue

func (q SqQueue) EnQueue(element any) SqQueue

type SqQueueInterface

type SqQueueInterface interface {
	// 进队列
	//  @param any
	EnQueue(any) SqQueue

	// 出队列
	//  @return SqQueue
	//  @return any
	DeQueue() (SqQueue, any)
}

type SqStack

type SqStack struct {
	Data []any
	Top  int //栈顶指针
}

SqStack 顺序栈,数组实现

func NewSqStack

func NewSqStack(capacity int) *SqStack

初始化操作,建立一个空栈,栈顶指针为-1

@param capacity
@return *SqStack

func (*SqStack) Flush

func (s *SqStack) Flush()

func (*SqStack) IsEmpty

func (s *SqStack) IsEmpty() bool

func (*SqStack) Pop

func (s *SqStack) Pop() any

func (*SqStack) Print

func (s *SqStack) Print()

func (*SqStack) Push

func (s *SqStack) Push(element any)

type SqStackInterface

type SqStackInterface interface {
	// 栈是否为空
	//  @return bool
	IsEmpty() bool

	// 进栈操作
	//  @param any
	Push(any)

	// 出栈操作
	//  @return any
	Pop() any

	// 打印栈
	Print()

	// 刷新栈
	Flush()
}

type TreeNode

type TreeNode struct {
	Value any
	Left  *TreeNode
	Right *TreeNode
}

二叉树节点

func Array2Tree

func Array2Tree(arr []any) *TreeNode

数组转二叉树,使用leetcode紧凑表示法

func NewTreeNode

func NewTreeNode(value any) *TreeNode

Jump to

Keyboard shortcuts

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