CJCoding With Joseph
15free / daySign inCreate account

Stack to Vector Bottom First

Write a function vector<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 line empty.

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
Topics:
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.