Top or None
easyQuestion 505Write a function string topOrNone(const stack<int>& s). If the stack is empty, return the string none. Otherwise return the top element converted to a string with to_string.
The tests print the returned string on its own line: for a stack whose top is 7 the output is 7, and for an empty stack the output is none.
Do NOT write a main function.
Expected output
7 none
= newline. The output ends with a newline, so 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.