← Back to STL Containers
Question 519
Stack to Vector Bottom First
Stack to Vector Bottom First
Write a functionvector<int> bottomFirst(stack<int> s)that returns the stack's contents as a vector ordered from the bottom of the stack to the top. Example: for a stack where 1, 2, 3 were pushed in that order (3 on top) the result is {1, 2, 3}, and the test prints the values separated by single spaces (see Expected Output). For an empty stack return an empty vector; the test then prints the lineempty. Do NOT write a main function.
Expected Output:
1 2 3 empty
= newline. The output ends with a newline — print one after the last line.
Hints4 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.