← Back to STL Containers
Question 504
Drain a Stack
Drain a Stack
Astack<int>namedsalready holds 1, 2, 3 (3 is on top). Write a loop that keeps printing the top element and popping it until the stack is empty. Print each value followed by a space; the final newline is already printed for you. Print exactly what is shown in Expected Output.
Expected Output:
3 2 1= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
STL ContainersStacks
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.