Function mergeQueues

  • Stable-merges two queues.

    Elements are compared using the binary predicate compare to determine the order in which they appear in the merged queue. Relative order of elements in the original queues is preserved. A new queue is created and returned if both queues to merge are not empty.

    Returns

    The merged queue if both queues to merge are not empty, one of the queues to merge if the other is empty, null if both are empty.

    Throws

    Error if the two queues to merge are of different queue types.

    Note

    The complexity of the merge algorithm is O(n1 + n2) in both time and space, where n1 and n2 are the sizes of the two queues to merge.

    Type Parameters

    • T

      Type of the elements in the two queues to merge.

    Parameters

    • queue1: Readonly<IQueue<T>>

      A queue to merge. No change after operation.

    • queue2: Readonly<IQueue<T>>

      Another queue to merge. No change after operation.

    • compare: ((elem1: T, elem2: T) => boolean)

      A callable object that determines the element order in the merged queue; it has not effect on the relative order of elements in the original queues.

        • (elem1: T, elem2: T): boolean
        • Parameters

          • elem1: T
          • elem2: T

          Returns boolean

    Returns IQueue<T> | null

Generated using TypeDoc