maxheap

package
v0.0.0-...-73e22f4 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package maxheap is an implementation of minheap data structure in go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Heap

type Heap struct {
	// contains filtered or unexported fields
}

Heap struct contains data and methods for heap implementation

func BuildHeap

func BuildHeap(data []int) *Heap

BuildHeap builds heap structure from an unorganized data list Time complexity of building a heap is O(n)

func NewHeap

func NewHeap() *Heap

NewHeap creates new empty 1-indexed heap

func (*Heap) ExtractMax

func (h *Heap) ExtractMax() (int, error)

ExtractMax returns the maximum value (i.e. root) in the heap and removes it from the heap. Returns error, if heap is empty

func (*Heap) Insert

func (h *Heap) Insert(d int)

Insert inserts new element into heap

func (*Heap) Length

func (h *Heap) Length() int

Length returns total number of elements currently present in heap

func (*Heap) Max

func (h *Heap) Max() (int, error)

Max returns the maximum value (i.e. root) in the heap, without removing it. Returns error, if heap is empty

Jump to

Keyboard shortcuts

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