Implement a Stack class with a fixed capacity on top of a private std::vector, offering push, pop, top, size and empty; push must report overflow and pop must report underflow.
push 10 ok
push 20 ok
push 30 ok
push 40 overflow
pop 30
pop 20
pop 10
pop underflow, size 0
Callers cannot reach the vector, so the stack can only be used last-in-first-out and can never exceed its capacity. std::optional expresses "maybe a value" for pop.
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!
We use Google Analytics cookies to see how LearnFrenzy is used and make it better, and Google AdSense to keep it free.
No analytics or ad cookies are set until you accept. Privacy Policy
·
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!