A simple way of implementing the stack ADT is using an array where we add elements left to right and a variable keeps track of the index of the top element. The array storing the stack elements may become full, a push operation will then throw a FullStackException.
In terms of performance:
- Let be the number of elements in the stack.
- The space used is
- Each operation runs in time
Limitations:
- The maximum size of the stack must be defined ahead of time and cannot be changed.
- Trying to push a new element into a full stack causes an implementation specific exception.