Stacks
In my last post, I talked about dynamic arrays. One use of a dynamic array is to implement a stack. Stacks are LIFO, dynamic in size, and supports three operations — push, pop, and peek. Pushing pushes an element to the top of the stack. Say we push items from an array into a stack
As we push objects to the top, we follow the LIFO principle. Likewise, we can pop elements as long as we follow the same principle.
And finally peek is where we return the top element without removing it from the stack.