TOPIC 17.1.1
Stacks and Their Uses


A stack is a limited version of an array. New nodes can be added to a stack and removed from a stack only from one end. For this reason, a stack is referred toa as a LIFO structure (Last-In First-Out).

Stacks have many applications. For example, when a function call is made, the called function must know how to return to back to the program, so the current address of program execution is pushed onto a stack. Once the function is finished, the address that was saved is removed from the stack, and execution of the program resumes. If a series of function calls occur, the successive return values are pushed onto the stack in LIFO order so that each function can return back to calling program. Stacks support recursive function calls in the same manner as conventional nonrecursive calls.

Stacks are also used by compilers in the process of evaluating expressions and generating machine language code.