CJCoding With Joseph
15free / daySign inCreate account

Reverse a Queue Using a Stack

Write a function void reverseQueue(queue<int>& q) that reverses the order of the elements in q in place, using a stack<int> as a helper. The function must also work on an empty queue (it simply leaves it empty).

The first test reverses a queue holding 1, 2, 3 (1 at the front), drains it and prints the output shown in Expected Output.

The second test reverses an empty queue and prints:
empty

Do NOT write a main function.

Expected Output:

3 2 1
empty

= 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.