Interleave Two Queues
mediumQuestion 495Write a function queue<int> interleave(queue<int> a, queue<int> b) that returns a new queue built by alternating elements: first the front of a, then the front of b, then the next element of a, then the next of b, and so on. When one queue runs out, append all remaining elements of the other.
The tests drain the returned queue and print the values separated by spaces. For a = {1, 2, 3} and b = {10, 20} the output is exactly what is shown in Expected Output.
For a = {1, 2} and b = {10, 20, 30, 40} the output is: 1 10 2 20 30 40
Do NOT write a main function.
Expected output
1 10 2 20 3 1 10 2 20 30 40
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
STL ContainersQueues
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.