Reverse a Queue Using a Stack
mediumQuestion 492Write 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, 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.