Everyone should know the concept and operation of a stack by now. We encountered stack data structures when discussing call stacks and evaluation stacks.
Stacks are last-in, first-out (LIFO) collections. Compare it to a stack of books where it’s (nearly) impossible to get a book other than the one at the top without popping the books on top of it off the stack first. The basic operations are called
Pop, and a
Peek method allows looking at the top element without popping it off. Figure 16.4 graphically depicts the operation of a stack.
To illustrate the use of a stack, take a look ...