Stacks and Queues

Stacks and queues are fundamental patterns for processing lists.

Stacks

A stack is a last in, first out operation. Think of a stack of plates.

When a program executes, it runs a function that calls other functions.

These make up the program's call stack.

As it executes line by line, it descends into each function being called, and then returns to the next line.

Using a debugger, we can stop the program's execution on a line of code, and view the call stack, showing a list of functions that were called before this one.

Queues

A queue is a first in, first out operation. Think of waiting in line.

Queues are used for processing a series of items.

Level
Topics