Figures 6.3 and 6.4 show a sample stack, in memory, before and after a fifth item is added to the stack. At each point, the top of the stack points to the top-most element. After the new element is added, the top of the stack points at the newest element, and that element’s link points to the item that used to be at the top of the stack.
Figure 6.3: A sample stack, just before adding a fifth item
Figure 6.4: The same stack, after adding the new item
It takes very little code to create and maintain a stack. The structure requires two class modules: the Stack and StackItem classes.