Definition

  • A collection of items, which are accessed in Last In First Out (LIFO) order
  • Only the top (head) can be viewed (via peek) or returned (via pop)
  • Adding new items is referred to as pushing
  • Removing items is referred to as popping
  • The last item to enter a stack is the first to come out of it

Signature

name stack;
import elem, boolean;
ops:
	newStack : → stack; 
	push : stack × elem → stack;
	pop : stack → stack; 
	top : stack → elem; 
	isEmpty : stack → boolean; 
	etc.