# mergePQ -- merges two queues

## Synopsis

• Usage:
Q = mergePQ(Q,R)
• Inputs:
• Outputs:
• Q, an instance of the type PriorityQueue, the same PriorityQueue as the first input, now with the second merged into it

## Description

The output of the function is the priority queue whose elements are the disjoint union of the elements of Q and R. Note that Q is altered in the process to become the merged queue.

 i1 : Q = priorityQueue {2,4,6} o1 = PriorityQueue{...4...} o1 : PriorityQueue i2 : R = priorityQueue {1,3,5} o2 = PriorityQueue{...4...} o2 : PriorityQueue i3 : mergePQ(Q,R) o3 = PriorityQueue{...4...} o3 : PriorityQueue i4 : pop Q o4 = 1 i5 : pop Q o5 = 2

## Caveat

The priority queue Q is mutable and is altered by mergePQ. The elements of Q and R must be comparable to each other.

## Ways to use mergePQ :

• "mergePQ(PriorityQueue,PriorityQueue)"

## For the programmer

The object mergePQ is .