CJCoding With Joseph
15free / daySign inCreate account

Top or None

Write 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 — print one after the last line.

Hints3 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.