Book contents
1 - Elementary Structures
Published online by Cambridge University Press: 25 January 2011
Summary
Elementary data structures usually treated in the “Programming 2” class are the stack and the queue. They have a common generalization, the double-ended queue, which is also occasionally mentioned, although it has far fewer applications. Stack and queue are very fundamental structures, so they will be discussed in detail and used to illustrate several points in data structure implementation.
Stack
The stack is the simplest of all structures, with an obvious interpretation: putting objects on the stack and taking them off again, with access possible only to the top item. For this reason they are sometimes also described as LIFO storage: last in, first out. Stacks occur in programming wherever we have nested blocks, local variables, recursive definitions, or backtracking. Typical programming exercises that involve a stack are the evaluation of arithmetic expressions with parentheses and operator priorities, or search in a labyrinth with backtracking.
The stack should support at least the following operations:
{push (obj): Put obj on the stack, making it the top item.
{pop (): Return the top object from the stack and remove it from the stack.
{stack empty (): Test whether the stack is empty.
Also, the realization of the stack has, of course, to give the right values, so we need to specify the correct behavior of a stack. One method would be an algebraic specification of what correct sequences of operations and return values are.
- Type
- Chapter
- Information
- Advanced Data Structures , pp. 1 - 22Publisher: Cambridge University PressPrint publication year: 2008