← Back to STL Containers
Question 508
Push All from a Vector
Push All from a Vector
Write a functionvoid pushAll(stack<int>& s, const vector<int>& v)that pushes every element ofvontos, in order fromv[0]to the last element (so the last element ofvends up on top). The loop header is already written. The tests then print the top and the size of the stack, for example for an empty stack and v = {4, 5, 9} (see Expected Output). Do NOT write a main function.
Expected Output:
Top: 9 Size: 3 Top: 40 Size: 4
= newline. The output ends with a newline — print one after the last line.
Hints2 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.