next up previous index
Next: Simple Implementation Up: Data Structures Previous: Array Access and Memory   Index


Stacks

A stack is a data-structure providing two basic methods, usually called push and pop. It is a way of buffering a stream of objects, in which the last in is first out (LIFO). The objects could be data items for processing, instructions pending execution, etc.

A common picture is that of a pile of plates. The first plate begins the pile. The next is placed on top of the first, and the next on top of that, and so on. A plate may be removed from the pile at any time, but only from the top. The order of pushing plates onto the pile or popping them from the top is arbitrary. There will always be a certain number of plates on the pile. Pushing a plate onto the pile increases the number by one; popping a plate decreases it by one. But naturally you cannot pop a plate off an empty pile. Nor can you push a plate onto a full one--at least if there is a maximum number of plates the pile can hold. So these two conditions need to be monitored.



Subsections
next up previous index
Next: Simple Implementation Up: Data Structures Previous: Array Access and Memory   Index
Peter Williams 2005-06-07