A stack is a list with the restriction that inserts and deletes can be performed in only one position, namely the end of ofthe list called the top. The fundamental operations on a stack are push, which is equivalent to an insert, and pop, whichdeletes the most recently inserted element. The most recently inserted element can be examined prior to performing a pop by use of the top routine. A pop or top on an empty stack is generally considered an error in the stack ADT. On the other hand, running out of space when performing a push is an implementation error but not an ADT error.
Stacks are sometimes known as LIFO (last in, first out) lists. The model depicted in Figure 3.37 signifies only thatpushes are input operations and pops and tops are output. The usual operations to make