heap-min-max

    1.0.4 • Public • Published

    heap-min-max

    Min heap and max heap for NodeJS

    Example

    min heap

     
    const MinHeap = require("heap-min-max").MinHeap;
     
    let minHeap = new MinHeap();
    minHeap.push(5, "v5");
    minHeap.push(3, "v3");
    minHeap.push(2, "v2");
    minHeap.push(4, "v4");
    minHeap.push(1, "v1");
     
    let x;
    while ((= minHeap.pop()) !== undefined){
        console.info(x);
    }
     

    output

    v1
    v2
    v3
    v4
    v5

    max heap

    const MaxHeap = require("heap-min-max").MaxHeap;
     
    let maxHeap = new MaxHeap();
    maxHeap.push(5, "v5");
    maxHeap.push(3, "v3");
    maxHeap.push(2, "v2");
    maxHeap.push(4, "v4");
    maxHeap.push(1, "v1");
     
    let x;
    while ((= maxHeap.pop()) !== undefined){
        console.info(x);
    }

    output

    v5
    v4
    v3
    v2
    v1

    Install

    npm i heap-min-max

    DownloadsWeekly Downloads

    3

    Version

    1.0.4

    License

    Apache-2.0

    Last publish

    Collaborators

    • reanote