You can use a stack when you need to remember something and only ever need the last thing.

If you need to access any item in a collection at any time, then a stack is not going to work. I didn’t explain stacks before because in a way, it’s like a restricted vector. Make sure to listen to the earlier episodes 39 through 46 for more information about other collections. You’ll want to use a stack whenever you need to stop what your’e doing, remember everything so you can come back to your paused task later, and then go do something else.

A stack gives you two basic operations, push and pop. When you call push, you’re adding something to the top of the stack. Think of it like a deck of cards. Pushing will place a new card on top of the stack. The other operation is pop and this removes whatever is currently on top of the stack.

Make sure to listen to the full episode for examples and more details. And if you like these episodes, consider supporting the podcast by becoming a patron. The link is at the top and bottom of this page. For just $1 per month, you can get an additional podcast episode available only to patrons. The first patron episode begins Nov-2017.