ovidiugiorgi / heapjs

Minimal implementation for the Heap data structure in JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HeapJS

Simple Heap implementation for JavaScript.

Supported Operations

  • push: O(logN)
  • peek: O(1)
  • pop: O(logN)
  • isEmpty: O(1)

Comparator

  • default configuration is for a Min-Heap.
  • if you need let's say a Max-Heap, you can pass a custom comparator function to the constructor:
const heap = new Heap((a, b) => -1 * (a - b));
heap.push(7);
heap.push(5);
heap.push(10);
heap.pop(); // 10
heap.pop(); // 7
heap.pop(); // 5

About

Minimal implementation for the Heap data structure in JavaScript


Languages

Language:JavaScript 100.0%