heap

package module
v0.0.0-...-3afcfc1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 2 Imported by: 0

README

heap

heap sort in go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExampleCustomizedType

func ExampleCustomizedType()

func ExampleMaxHeap

func ExampleMaxHeap()

func ExampleMinHeap

func ExampleMinHeap()

Types

type Compare

type Compare[T any] func(x, y T) bool

Compare : every customized type should hava Compare function

type Heap

type Heap[T any] interface {
	// Push return a value into heap
	Push(T)
	// Pop return a value from top of heap,
	//  Attention: pop an empty heap will panic
	Pop() T
	// Peak return the top value of elements in heap
	Peak() *T
	// Len return the length of elements in heap
	Len() int
	// Empty return true if heap is empty
	Empty() bool
}

Heap is an implement for heap sort

func NewContainerHeap

func NewContainerHeap[T any](comparator Compare[T], elems ...T) Heap[T]

func NewHeap

func NewHeap[T any](comparator Compare[T], elems ...T) Heap[T]

NewHeap comparator is required for customized type

func NewMaxHeap

func NewMaxHeap[T comparator](elems ...T) Heap[T]

func NewMinHeap

func NewMinHeap[T comparator](elems ...T) Heap[T]

Jump to

Keyboard shortcuts

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