Stack
Stacks are linear data structures in a LIFO (last-in, first-out) order. Now, what does that mean? Imagine a stack of plates. The last plate that you put on top of the stack is the first one you take out. Stacks work that way: the last value you add is the first one you remove.
- The most common functions in a stack are
push
,pop
,isEmpty
, andpeek
.
Since stacks are simply LIFO, retrieving data is very fast, as there is no lookup required.
- this also has the consequence that the size of the data stored must be known at compile-time.
Along with queues, stacks are the most the basic list types in computing
A stack has a number of useful applications:
- Backtracking to a previous state
- Expression evaluation and conversion