CJCoding With Joseph
15free / daySign inCreate account

Interleave Two Queues

Write 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 — print one after the last line.

Hints4 available
Topics:
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.