← Back to STL Containers
Question 492
Reverse a Queue Using a Stack
Reverse a Queue Using a Stack
Write a functionvoid reverseQueue(queue<int>& q)that reverses the order of the elements inqin place, using astack<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
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.