Encapsulated Stack
hardQuestion 565Build a class NumberStack that hides a private List<int>. Provide:
- Push(int n) adds n to the top
- Pop() removes and returns the top (most recently pushed) item
- a read-only Count property with the number of items left
Do not write a Main method.
After Push(1), Push(2), Push(3), the program prints Pop() on one line then Count on the next (see Expected Output).
Expected output
3 2
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Encapsulation
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cw, cr, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.