Chapter 3
Stacks

3.1 Specification

A special case of lists in which restrictions are placed on where insertions and deletions can take place.

AbstractDataType Stack{ 
  instances 
     linear list of element, with top and bottom elements 
  operations 
    Create() 
    IsEmpty() 
    IsFull() 
    Top() 
    Add(x) 
    Delete() 
} 

3.2 Array Representation

      |---|
 max  |10 |
      ----
      |   |
length |5--|
      |---|--|-------|---|---|--|---|---|
      |e1 |e2|  ...   |en |   |  |   |   |
      ----------------------------------

3.3 One-way Linked Representation

   |---|
top | 5 |
   ----
    |---|                  |---|   |---|  |---|
    |   ||----       -|------  ||----  ||---- |
    |---|                  |---|   |---|  |---|
    |e1 |                  en-2|   en-1|  |en |
    ----                   ----    ----   ----