Professional Documents
Culture Documents
Week 6
We refer to the ‘top of the stack’ or the ‘buttom of the stack’, thus the number will be set out vertically, to
reinforce this point visually.
We also have the phrase ‘pushed on the top of the stack’ to indicate that an item of data has been added to
the stack.
Moreover, we have the phrase ‘popped off the stack’ to indicate that the ‘last number in’ is always the ‘first
number out’
The system of storing this list of numbers is called LIFO stack (Last In First Out).
A Pointer System
In practice a stack would be built up in the computer’s memory using a pointer system. This is a number
used to pint to an item of interest, so it may be used to point to the memory location inside the computer that
indicates the top of the stack. (called Stack Pointer)
23 Add number 77
77
54 (PUSH) 23
10 54
90 10
90
Note: if there is no room to add a new item then a error message must be generated, as an overflow has
occurred. Example: (Let’s assume that an array STACK(N) has been already set up.)
Note: here the stack cannot overflow from this operation. However, there might be no items of data on the
stack, in which case cannot remove any more data.
Note: in this operation the data does not move, it is just the pointers that have been altered. We have the
start pointer (indicating to the head of the queue) and stop pointer (indicating to the end of the queue).
Size variables that represents the size of the queue. (Data elements in the queue)
QUEUE(pointer) subscripted variable representing the data at the current pointer position, i.e. an
identifier for the data on the queue.
What is a pointer?
A pointer is simply a data element that indicates the position of some other data element (e.g. the data
element that points to the top of the stack).
What is an Overflow?
A queue or a stack may have a maximum size. An attempt to add a new element to a queue or stack which
is already full will result in an overflow error.
What is an Underflow?
An attempt to remove an item from an empty queue or stack will result in an underflow.