Stack

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 Push and 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.

Image

FIGURE 16.4 Operation of a stack data structure.

To illustrate the use of a stack, take a look ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.