next up previous contents
Next: Module Global Data Example Up: Modules - Global Data Previous: Modules - Global Data

 

Module Global Data Example

  figure9547
Figure 25: How a Stack Works

A stack can be thought of as a pile of things that can only be accessed from the top. You can put something on the top of the pile: a Push action, and you can grab things off the top of the pile: a Pop action.

The diagrams show the conventional visualisation of a stack. As elements are pushed onto the top of the stack, the previous top elements get pushed down, as things are popped off the top the lower stack entries move towards the top.

Return to corresponding overview page gif  

  figure9568
Figure 26: How a Stack Could be Implemented

These diagrams show how we will simulate the stack using an array with a pointer to indicate where the top of the stack is. As elements are pushed onto the stack they are stored in the array and the `top' position moves right; as things are popped off, the top of the stack moves left. From this description it can be seen that we need three objects to simulate a stack:

This data is needed by both the Push and Pop procedures, and should be made global. Return to corresponding overview page gif


next up previous contents
Next: Module Global Data Example Up: Modules - Global Data Previous: Modules - Global Data

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.