Class PriorityQueue<E>

Type Parameters

  • E = any

Hierarchy

Constructors

Properties

_comparator: PriorityQueueComparator<E> = ...
_nodes: E[] = []

Accessors

Methods

  • 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 | E)[]

    an array of type (E | null)[].

  • 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.

  • 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.

  • 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.

  • 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.

  • 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.

  • 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

  • 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

  • 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.

  • 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

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

    Parameters

    • node: E

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

    Returns void

  • 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 E[]

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

    Parameters

    • node: E

      The parameter node is of type E, 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.

  • 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.

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

    Returns null | E

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

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

    Returns null | E

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

  • The heapify function creates a new PriorityQueue instance and fixes the heap property.

    Type Parameters

    • E

    Parameters

    • options: PriorityQueueOptions<E>

      The "options" parameter is an object that contains the configuration options for the PriorityQueue. It can include properties such as "comparator" which specifies the comparison function used to order the elements in the priority queue, and "initialValues" which is an array of initial values to be added to the priority

    Returns PriorityQueue<E>

    a new instance of the PriorityQueue class after performing the heapify operation on it.

  • 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

    • E

    Parameters

    • options: Omit<PriorityQueueOptions<E>, "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.

Generated using TypeDoc