4.1.2 Stacks
Computational Structures
A stack is a simple data structure where you can only add or remove items from one end, known as the “top”. Both insertion and deletion of elements occur at this top end. A stack operates on the Last-In, First-Out (LIFO) principle, meaning that the most recently added element is the first one to be removed.
4.1.2.1 Properties of Stack
- LIFO Principle: A stack works by the Last-In, First-Out rule. The last item added is the first one removed.
- Single Access Point: You can only add or remove items from the top of the stack.
- Order Preservation: The order in which you add items is preserved, with the last item added being the first to leave.
- Size Flexibility: A stack can either have a fixed size or grow as needed.
Sequential Access: You can only access items in the order they were added, starting from the top.