Type Parameters

  • T extends NodeData = number

Hierarchy

  • Heap

Implements

  • IHeap<T>

Constructors

Methods

Constructors

  • Example


    const heapOptions = {
    cmp: (a, b) => a < b // max heap comparator "Default"
    }

    // You can remove type specification and it will default to number
    const h = new Heap([], heapOptions);

    Type Parameters

    • T extends unknown = number

    Parameters

    • data: T[] = []

      Array of elements to push into the heap

    • Optional options: HeapOptions<T>

      Heap options

    Returns Heap<T>

Methods

  • Get the current size of the heap

    Returns

    Example

    const h = Heap();
    const size = h.push(1).push(2).push(5).size(); // 3

    Returns number

  • Retrieve the top element in the heap

    Returns

    Example

    const h = Heap();
    const peak = h.push(1).push(2).push(3).peak(); // 3

    Returns T

  • pop the top of the heap

    Returns

    self reference

    Example

    const h = Heap();
    h.push(1).push(2).push(3).pop();

    Returns Heap<T>

  • Push data into the heap

    Returns

    self reference

    Example

    const h = Heap();
    h.push(1).push(2).push(3);

    Parameters

    • data: T

    Returns Heap<T>

  • View the heap

    Returns

    Example

    const h = Heap();
    h.push(1).push(2).push(5).view(); //[ 5 , 2 , 1 ]

    Returns Heap<T>

Generated using TypeDoc