← Back to STL Containers
Question 495
Interleave Two Queues
Interleave Two Queues
Write a functionqueue<int> interleave(queue<int> a, queue<int> b)that returns a new queue built by alternating elements: first the front ofa, then the front ofb, then the next element ofa, then the next ofb, 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 — 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.