1.0.0 • Published 10 months ago

namastey-max-heap v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

namastey-max-heap

A package implementing Max-Heap data structure

Features

  • insert(value): Inserts a new value into the heap while maintaining the max-heap property.
  • extractMax(): Removes and returns the maximum value (root) from the heap.
  • peek(): Returns the maximum value (root) without removing it from the heap.
  • getSize(): Returns the current size of the heap.
  • isEmpty(): Checks if the heap is empty.

Installation

To install the package globally, use the following command:

npm install -g namastey-max-heap

Examples

const MaxHeap = require('namastey-max-heap');

const heap = new MaxHeap();
heap.insert(10);
heap.insert(20);
heap.insert(5);
heap.insert(30);

console.log('Max value:', heap.extractMax()); // Output: Max value: 30
console.log('Max value:', heap.peek()); // Output: Max value: 20
console.log('Heap size:', heap.getSize()); // Output: Heap size: 3
console.log('Is heap empty?', heap.isEmpty()); // Output: Is heap empty? false