Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Heap

A Heap is a special Tree-based data structure in which the tree is a complete binary tree

Examples

const { Heap } = require('dsajs');
// or  
// import { Heap } from 'dsajs';
let maxHeap = new Heap((a,b) => b>a);
let minHeap = new Heap((a,b) => a>b);

Hierarchy

  • Heap

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • new Heap(compareFn: CompareFunction): Heap
  • Parameters

    • compareFn: CompareFunction

      (a,b) => return true if b should be before a else false

    Returns Heap

Properties

Private _

_: any[]

Private compareFn

compareFn: CompareFunction

Accessors

size

  • get size(): number

top

  • get top(): any

Methods

add

  • add(data: any): void

clear

  • clear(): void

heapify

  • heapify(): void

isEmpty

  • isEmpty(): boolean

popTop

  • popTop(): any
  • Remove the top of heap and return

    Returns any

    the top element or undefined if heap is empty

toArray

  • toArray(): any[]

Generated using TypeDoc