8. The STACK

A LIST is a very general computer data structure. However, there are certain types of list that are so common, they are given their own name.

The 'STACK' is a Last-In First-Out (LIFO) List. Only the last item in the stack can be accessed directly.

If you had a number of items added to a stack in this order 1. 'Dog', 2. 'Cat', 3. 'Horse', the stack would look like this

Horse (last in)
Dog (first in)

The standard operations on a stack are

Operations on a stack
PUSH Adds an item to the top of the stack
POP Removes an item from the top of the stack
TOP Identifies the item at the top of the stack, but does not remove it


One of the most common uses for a stack in computer programming is to use it to control program flow within an application.

The next page describes a typical use of the stack data structure.



Copyright © www.teach-ict.com