Linked Implementation Of Stacks
One node for each element in the stack. Each node contains:
- the value of the element
- a pointer to the node for the next element.
Thus, stack S = { 29, 7, 11 } is implemented by:
- Each node contain 2 pieces of information: they must be
structures.
S
is not a node, but it points to the node for the
first element. It could be implemented simply by a pointer.
How to represent the empty stack?
S
could also keep track of the number of elements
in the stack.
- or it could be equipped with a boolean flag.
- or we could set
S
's pointer to ``the first
element'' to NULL
when the stack is empty.