Documentation ¶
Overview ¶
Package datastructure implements some data structure. eg. list, linklist, stack, queue, tree, graph.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MaxHeap ¶
type MaxHeap[T any] struct { // contains filtered or unexported fields }
MaxHeap implements a binary max heap type T should implements Compare function in lancetconstraints.Comparator interface.
func BuildMaxHeap ¶ added in v2.1.5
func BuildMaxHeap[T any](data []T, comparator lancetconstraints.Comparator) *MaxHeap[T]
BuildMaxHeap builds a MaxHeap instance with data and given comparator.
func NewMaxHeap ¶
func NewMaxHeap[T any](comparator lancetconstraints.Comparator) *MaxHeap[T]
NewMaxHeap returns a MaxHeap instance with the given comparator.
func (*MaxHeap[T]) Peek ¶
Peek returns the largest element from the heap without removing it. if heap is empty, it returns zero value and false.
func (*MaxHeap[T]) Pop ¶
Pop return the largest value, and remove it from the heap if heap is empty, return zero value and fasle
func (*MaxHeap[T]) PrintStructure ¶
func (h *MaxHeap[T]) PrintStructure()
PrintStructure print the structure of the heap