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

# Class MaxPriorityQueue<T>

#### Type Parameters

- #### T = number

#### Hierarchy

- PriorityQueue <T>
  - MaxPriorityQueue

- Defined in src/data-structures/priority-queue/max-priority-queue.ts:11

#####
Index

### Constructors

constructor

### Properties

_comparator
_nodes

### Accessors

nodes
size

### Methods

DFS
_compare
_fix
_getComparedChild
_getLeft
_getParent
_getRight
_heapifyDown
_heapifyUp
_isValidIndex
_setNodes
_swap
add
clear
clone
getNodes
has
isEmpty
isValid
leaf
peek
poll
sort
toArray
heapify
isPriorityQueueified

## Constructors

### constructor

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

- The constructor initializes a priority queue with an optional comparator function.

  #### Type Parameters

  - #### T = number

  #### Parameters

  - ##### `Optional` options: Omit< PriorityQueueOptions <number>, "comparator">

    The `options` parameter is an optional object that can contain various properties to configure the priority queue.

  #### Returns MaxPriorityQueue <T>

  Overrides PriorityQueue.constructor

  - Defined in src/data-structures/priority-queue/max-priority-queue.ts:12
- new MaxPriorityQueue<T>(options): MaxPriorityQueue <T>

- The constructor initializes a priority queue with an optional comparator function.

  #### Type Parameters

  - #### T = number

  #### Parameters

  - ##### options: PriorityQueueOptions <T>

    The `options` parameter is an optional object that can contain various properties to configure the priority queue.

  #### Returns MaxPriorityQueue <T>

  Overrides PriorityQueue<T>.constructor

  - Defined in src/data-structures/priority-queue/max-priority-queue.ts:13

## Properties

### `Protected` `Readonly` _comparator

_comparator: PriorityQueueComparator <T> = ...

Inherited from PriorityQueue._comparator

- Defined in src/data-structures/priority-queue/priority-queue.ts:237

### `Protected` _nodes

_nodes: T[] = []

Inherited from PriorityQueue._nodes

- Defined in src/data-structures/priority-queue/priority-queue.ts:27

## Accessors

### nodes

- get nodes(): T[]

- #### Returns T[]

  Inherited from PriorityQueue.nodes

  - Defined in src/data-structures/priority-queue/priority-queue.ts:29

### size

- get size(): number

- #### Returns number

  Inherited from PriorityQueue.size

  - Defined in src/data-structures/priority-queue/priority-queue.ts:33

## Methods

### DFS

- DFS(dfsMode): (null | T)[]

- The DFS function performs a depth-first search traversal on a binary tree and returns an array of visited nodes based on the specified traversal order.

  #### Parameters

  - ##### dfsMode: PriorityQueueDFSOrderPattern

    The dfsMode parameter is a string that specifies the order in which the nodes should be visited during the Depth-First Search (DFS) traversal. It can have one of the following values:

  #### Returns (null | T)[]

  an array of type `(T | null)[]`.

  Inherited from PriorityQueue.DFS

  - Defined in src/data-structures/priority-queue/priority-queue.ts:204

### `Protected` _compare

- _compare(a, b): boolean

- The function compares two numbers using a custom comparator function.

  #### Parameters

  - ##### a: number

    The parameter "a" is a number that represents the index of a node in an array.

  - ##### b: number

    The parameter "b" is a number.

  #### Returns boolean

  the result of the comparison between the elements at indices `a` and `b` in the `nodes` array. The comparison is done using the `_comparator` function, and if the result is greater than 0, `true` is returned, indicating that the element at index `a` is greater than the element at index `b`.

  Inherited from PriorityQueue._compare

  - Defined in src/data-structures/priority-queue/priority-queue.ts:251

### `Protected` _fix

- _fix(): void

- The _fix function performs a heapify operation on the elements of the heap starting from the middle and moving towards the root.

  #### Returns void

  Inherited from PriorityQueue._fix

  - Defined in src/data-structures/priority-queue/priority-queue.ts:354

### `Protected` _getComparedChild

- _getComparedChild(parent): number

- The function returns the index of the smallest child node of a given parent node.

  #### Parameters

  - ##### parent: number

    The parent parameter is a number that represents the index of the parent node in a binary tree.

  #### Returns number

  the minimum value between the parent node and its left and right child nodes.

  Inherited from PriorityQueue._getComparedChild

  - Defined in src/data-structures/priority-queue/priority-queue.ts:309

### `Protected` _getLeft

- _getLeft(parent): number

- The function returns the index of the left child node in a binary tree given the index of its parent node.

  #### Parameters

  - ##### parent: number

    The parameter "parent" is a number that represents the index of a node in a binary tree.

  #### Returns number

  the left child of a given parent node in a binary tree.

  Inherited from PriorityQueue._getLeft

  - Defined in src/data-structures/priority-queue/priority-queue.ts:290

### `Protected` _getParent

- _getParent(child): number

- The function returns the index of the parent node given the index of a child node in a binary tree.

  #### Parameters

  - ##### child: number

    The "child" parameter is a number representing the index of a child node in a binary tree.

  #### Returns number

  the parent of the given child node.

  Inherited from PriorityQueue._getParent

  - Defined in src/data-structures/priority-queue/priority-queue.ts:281

### `Protected` _getRight

- _getRight(parent): number

- The function returns the index of the right child node in a binary tree given the index of its parent node.

  #### Parameters

  - ##### parent: number

    The parameter "parent" is a number that represents the index of a node in a binary tree.

  #### Returns number

  the right child of a given parent node in a binary tree.

  Inherited from PriorityQueue._getRight

  - Defined in src/data-structures/priority-queue/priority-queue.ts:299

### `Protected` _heapifyDown

- _heapifyDown(start): void

- The function performs a heapify operation by comparing and swapping elements in a binary heap.

  #### Parameters

  - ##### start: number

    The start parameter is the index of the element in the heap from where the heapifyDown operation should start.

  #### Returns void

  Inherited from PriorityQueue._heapifyDown

  - Defined in src/data-structures/priority-queue/priority-queue.ts:341

### `Protected` _heapifyUp

- _heapifyUp(start): void

- The function `_heapifyUp` is used to maintain the heap property by moving an element up the heap until it is in the correct position.

  #### Parameters

  - ##### start: number

    The start parameter is the index of the element that needs to be moved up in the heap.

  #### Returns void

  Inherited from PriorityQueue._heapifyUp

  - Defined in src/data-structures/priority-queue/priority-queue.ts:328

### `Protected` _isValidIndex

- _isValidIndex(index): boolean

- The function checks if a given index is valid within an array.

  #### Parameters

  - ##### index: number

    The parameter "index" is of type number and represents the index value that needs to be checked for validity.

  #### Returns boolean

  A boolean value indicating whether the given index is valid or not.

  Inherited from PriorityQueue._isValidIndex

  - Defined in src/data-structures/priority-queue/priority-queue.ts:272

### `Protected` _setNodes

- _setNodes(value): void

- #### Parameters

  - ##### value: T[]

  #### Returns void

  Inherited from PriorityQueue._setNodes

  - Defined in src/data-structures/priority-queue/priority-queue.ts:233

### `Protected` _swap

- _swap(a, b): void

- The function swaps two elements in an array.

  #### Parameters

  - ##### a: number

    The parameter "a" is a number that represents the index of an element in an array.

  - ##### b: number

    The parameter "b" is a number.

  #### Returns void

  Inherited from PriorityQueue._swap

  - Defined in src/data-structures/priority-queue/priority-queue.ts:260

### add

- add(node): void

- The "add" function adds a node to the heap and ensures that the heap property is maintained.

  #### Parameters

  - ##### node: T

    The parameter "node" is of type T, which means it can be any data type. It represents the node that needs to be added to the heap.

  #### Returns void

  Inherited from PriorityQueue.add

  - Defined in src/data-structures/priority-queue/priority-queue.ts:73

### clear

- clear(): void

- The clear function clears the nodes array.

  #### Returns void

  Inherited from PriorityQueue.clear

  - Defined in src/data-structures/priority-queue/priority-queue.ts:135

### clone

- clone(): PriorityQueue <T>

- The `clone` function returns a new instance of the `PriorityQueue` class with the same nodes and comparator as the original instance.

  #### Returns PriorityQueue <T>

  The `clone()` method is returning a new instance of the `PriorityQueue` class with the same `nodes` and `comparator` properties as the original instance.

  Inherited from PriorityQueue.clone

  - Defined in src/data-structures/priority-queue/priority-queue.ts:153

### getNodes

- getNodes(): T[]

- Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.

  #### Returns T[]

  Inherited from PriorityQueue.getNodes

  - Defined in src/data-structures/priority-queue/priority-queue.ts:64

### has

- has(node): boolean

- The "has" function checks if a given node is present in the list of nodes.

  #### Parameters

  - ##### node: T

    The parameter `node` is of type `T`, which means it can be any type. It represents the node that we want to check if it exists in the `nodes` array.

  #### Returns boolean

  a boolean value indicating whether the given node is included in the array of nodes.

  Inherited from PriorityQueue.has

  - Defined in src/data-structures/priority-queue/priority-queue.ts:84

### isEmpty

- isEmpty(): boolean

- The function checks if the size of an object is equal to zero and returns a boolean value indicating whether the object is empty or not.

  #### Returns boolean

  The method `isEmpty()` is returning a boolean value indicating whether the size of the object is equal to 0.

  Inherited from PriorityQueue.isEmpty

  - Defined in src/data-structures/priority-queue/priority-queue.ts:128

### isValid

- isValid(): boolean

- The `isValid` function recursively checks if a binary tree satisfies a certain condition.

  #### Returns boolean

  The function `isValid()` returns a boolean value.

  Inherited from PriorityQueue.isValid

  - Defined in src/data-structures/priority-queue/priority-queue.ts:165

### leaf

- leaf(): null | T

- The `leaf` function returns the last element in the `nodes` array or `null` if the array is empty.

  #### Returns null | T

  The method `leaf()` is returning the last element (`T`) in the `nodes` array if it exists. If the array is empty or the last element is `null`, then it returns `null`.

  Inherited from PriorityQueue.leaf

  - Defined in src/data-structures/priority-queue/priority-queue.ts:118

### peek

- peek(): null | T

- The `peek` function returns the first element of the `nodes` array if it exists, otherwise it returns `null`.

  #### Returns null | T

  The `peek()` function is returning the first element (`T`) of the `nodes` array if the `size` is not zero. Otherwise, it returns `null`.

  Inherited from PriorityQueue.peek

  - Defined in src/data-structures/priority-queue/priority-queue.ts:93

### poll

- poll(): null | T

- The `poll` function removes and returns the top element from a heap data structure.

  #### Returns null | T

  The `poll()` method returns a value of type `T` or `null`.

  Inherited from PriorityQueue.poll

  - Defined in src/data-structures/priority-queue/priority-queue.ts:101

### sort

- sort(): T[]

- The function sorts the elements in a data structure and returns them in an array. Plan to support sorting of duplicate elements.

  #### Returns T[]

  The `sort()` method is returning an array of type `T[]`.

  Inherited from PriorityQueue.sort

  - Defined in src/data-structures/priority-queue/priority-queue.ts:188

### toArray

- toArray(): T[]

- The toArray function returns an array containing all the elements in the nodes property.

  #### Returns T[]

  An array of type T, which is the elements of the nodes property.

  Inherited from PriorityQueue.toArray

  - Defined in src/data-structures/priority-queue/priority-queue.ts:143

### `Static` heapify

- heapify<T>(options?): MaxPriorityQueue <T>

- The function `heapify` creates a max priority queue from the given options and returns it.

  #### Type Parameters

  - #### T extends number

  #### Parameters

  - ##### `Optional` options: Omit< PriorityQueueOptions <T>, "comparator">

    The `options` parameter is an object that contains configuration options for creating a priority queue. It can have the following properties:

  #### Returns MaxPriorityQueue <T>

  a MaxPriorityQueue object.

  Overrides PriorityQueue.heapify

  - Defined in src/data-structures/priority-queue/max-priority-queue.ts:33
- heapify<T>(options): MaxPriorityQueue <T>

- The function `heapify` creates a max priority queue from the given options and returns it.

  #### Type Parameters

  - #### T

  #### Parameters

  - ##### options: PriorityQueueOptions <T>

    The `options` parameter is an object that contains configuration options for creating a priority queue. It can have the following properties:

  #### Returns MaxPriorityQueue <T>

  a MaxPriorityQueue object.

  Overrides PriorityQueue.heapify

  - Defined in src/data-structures/priority-queue/max-priority-queue.ts:34

### `Static` isPriorityQueueified

- isPriorityQueueified<T>(options): boolean

- The function checks if a priority queue is valid by creating a new priority queue with a fix option and then calling the isValid method.

  #### Type Parameters

  - #### T

  #### Parameters

  - ##### options: Omit< PriorityQueueOptions <T>, "isFix">

    An object containing options for creating a priority queue. The options object should have the following properties:

  #### Returns boolean

  the result of calling the `isValid()` method on a new instance of the `PriorityQueue` class.

  Inherited from PriorityQueue.isPriorityQueueified

  - Defined in src/data-structures/priority-queue/priority-queue.ts:57

Generated using TypeDoc