In given K input streams of number in sorted order. You need to make a single output
Question:
In given K input streams of number in sorted order. You need to make a single output stream, which contains all the elements of the K streams in sorted order. The input streams support ReadNumber() operation and output stream support WriteNumber() operation.
a) Read the first number from all the K input streams and add them to a Priority Queue. (Nodes should keep track of the input stream;
data added to the PQ is value & stream id.)
b) Dequeue one element at a time from PQ, Put this element value to the output stream, Read the input stream number and from the same input stream add another element to PQ.
c) If the stream is empty, just continue
d) Repeat until PQ is empty.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Related Book For
Problems Solving In Data Structures And Algorithms Using C++
ISBN: 9789356273177
2nd Edition
Authors: Hemant Jain
Question Posted: