# MinHeap | data-structure-typed
Documentation for data-structure-typed

# Class MinHeap<T>

#### Type Parameters

- #### T

#### Hierarchy

- Heap <T>
  - MinHeap

- Defined in src/data-structures/heap/min-heap.ts:14

#####
Index

### Constructors

constructor

### Properties

_pq
_priorityCb

### Accessors

size

### Methods

clear
isEmpty
offer
peek
peekLast
poll
toArray

## Constructors

### constructor

- new MinHeap<T>(options?): MinHeap <T>

- The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem objects.

  #### Type Parameters

  - #### T

  #### Parameters

  - ##### `Optional` options: HeapOptions<T>

    The `options` parameter is an optional object that can be passed to the constructor. It is of type `HeapOptions<T>`, which is a generic type that represents the options for the heap.

  #### Returns MinHeap <T>

  Overrides Heap.constructor

  - Defined in src/data-structures/heap/min-heap.ts:23

## Properties

### `Protected` _pq

_pq: PriorityQueue <HeapItem<T>>

Overrides Heap._pq

- Defined in src/data-structures/heap/min-heap.ts:15

### `Protected` _priorityCb

_priorityCb: ((element) => number)

#### Type declaration

- - (element): number

  - #### Parameters

    - ##### element: T

    #### Returns number

Inherited from Heap._priorityCb

- Defined in src/data-structures/heap/heap.ts:10

## Accessors

### size

- get size(): number

- The function returns the size of a priority queue.

  #### Returns number

  The size of the priority queue.

  Inherited from Heap.size

  - Defined in src/data-structures/heap/heap.ts:33

## Methods

### clear

- clear(): void

- The clear function clears the priority queue.

  #### Returns void

  Inherited from Heap.clear

  - Defined in src/data-structures/heap/heap.ts:119

### isEmpty

- isEmpty(): boolean

- The function checks if a priority queue is empty.

  #### Returns boolean

  A boolean value indicating whether the size of the priority queue is less than 1.

  Inherited from Heap.isEmpty

  - Defined in src/data-structures/heap/heap.ts:41

### offer

- offer(element, priority?): Heap <T>

- The `offer` function adds an element to a priority queue with an optional priority value.

  #### Parameters

  - ##### element: T

    The `element` parameter represents the value that you want to add to the heap. It can be of any type.

  - ##### `Optional` priority: number

    The `priority` parameter is an optional number that represents the priority of the element being offered to the heap. If the `element` parameter is a number, then the `priority` parameter is set to the value of `element`. If the `element` parameter is not a number, then the

  #### Returns Heap <T>

  The `offer` method returns the instance of the `Heap` class.

  #### Throws

  if priority is not a valid number

  Inherited from Heap.offer

  - Defined in src/data-structures/heap/heap.ts:71

### peek

- peek(): null | HeapItem<T>

- The `peek` function returns the top item in the priority queue without removing it.

  #### Returns null | HeapItem<T>

  The `peek()` method is returning either a `HeapItem<T>` object or `null`.Returns an element with the highest priority in the queue

  Inherited from Heap.peek

  - Defined in src/data-structures/heap/heap.ts:49

### peekLast

- peekLast(): null | HeapItem<T>

- The `peekLast` function returns the last item in the heap.

  #### Returns null | HeapItem<T>

  The method `peekLast()` returns either a `HeapItem<T>` object or `null`.Returns an element with the lowest priority in the queue

  Inherited from Heap.peekLast

  - Defined in src/data-structures/heap/heap.ts:57

### poll

- poll(): null | HeapItem<T>

- The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an element with the highest priority in the queue

  #### Returns null | HeapItem<T>

  either a HeapItem<T> object or null.

  Inherited from Heap.poll

  - Defined in src/data-structures/heap/heap.ts:100

### toArray

- toArray(): HeapItem<T>[]

- The `toArray` function returns an array of `HeapItem<T>` objects.

  #### Returns HeapItem<T>[]

  An array of HeapItem<T> objects.Returns a sorted list of elements

  Inherited from Heap.toArray

  - Defined in src/data-structures/heap/heap.ts:112

Generated using TypeDoc