Help us shape the future of Go! Take the 2026 Go Developer Survey

heap

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const MaxData = math.MaxInt64
View Source
const MaxSize = 1000

Variables

This section is empty.

Functions

This section is empty.

Types

type Heap

type Heap struct {
	// 堆的大小
	Len int
	Cap int
	// 使用内部的数组来模拟树
	// 一个节点下标为 i,那么父亲节点的下标为 (i)/2
	// 一个节点下标为 i,那么左儿子的下标为 2i,右儿子下标为 2i+1
	Array []int
}

Heap 一个最大堆,一棵完全二叉树 最大堆要求节点元素都不小于其左右孩子

func NewHeap

func NewHeap() *Heap

NewHeap 初始化一个空堆,创建哨兵

func (*Heap) HeapSort

func (h *Heap) HeapSort()

HeapSort 堆排

func (*Heap) MaxHeap

func (h *Heap) MaxHeap(size int)

func (*Heap) Pop

func (h *Heap) Pop() int

Pop 最大堆移除根节点元素,也就是最大的元素

func (*Heap) Push

func (h *Heap) Push(x int)

Push 最大堆插入元素

Jump to

Keyboard shortcuts

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