Creating a Stack

A stack is a simple logical data structure, normally implemented using a linked list to contain its data. Of course, you could use an array to implement a stack, and many programmers have done this. A stack allows you to control data input and output in a very orderly fashion: new items can be added only to the top of the stack, and as you remove items, they too are removed from the top. In essence, a stack data structure works like the stack of cafeteria trays at your local eatery or like the pile of problems to solve on your desk (unless you’re compulsive and solve your problems in a queue-like fashion). This sort of data storage is often referred to as LIFO (Last In, First Out)—the most recent item added to the stack is the first to be removed.

© 1997 by SYBEX Inc. All rights reserved.