Stacks
What is a Stack? A stack is a type of data structure (a way of organizing and sorting data so that it can be used efficiently). To be specific, it’s a collection of objects that are inserted and removed according to the last in first out principle
It kind of like a pez dispenser When you add something to a stack it gets “pushed” onto the stack. And when something is removed it gets “popped” from the stack
Functions of a Stack Push- Inserts element e the top of the stack Pop- Removes the top element from the stack and returns it as a value Size- Returns the number of elements in a particular stack isEmpty- Tells whether the stack is empty or not Top- Returns the value top element of the stack
REAL LIFE EXAMPLES??? Web browsers use a stack to store the addresses of recently visited pages. New addresses get “pushed”. While pushing back button “pops” the previous page.