Data Structures

  1. Queue: A data structure that behaves in a sequential manner that is similar to a list, but abides by rules that are more strict than those of a list. Specifically, an element can be inserted into the queue only at the tail (end) of the queue and removed from the queue's head (start). A common term for this behavior is "First In, First Out" (FIFO).

    Queues are used by the OS, for example, when deciding what programs should run next on a CPU.

  2. Stack: Another sequential data structure. The difference between the stack and the queue is that the stack supports "Last In, First Out" (LIFO). That is, to access or remove an element from the stack, you must first remove all the elements lying on top of it.

    We'll return to stacks when we cover function-calling and recursion since their data are stored in a stack.

Both of these data structures are usually implemented with lists.