Unit 15: Stacks and Queues

  1. Introduction
  2. Queues
  3. Stacks
  4. Stack example: Screen navigation
  5. Stack example: Undo
  6. Queue example: Processing items
  7. Stack and Queue functionality

  8. Example code and additional resources

This week's stuff:


Stacks and Queues are two types of restricted-access data types. As we will see, they can be built on top of another structure, such as an array or a linked list, but they won't expose all the functionality of their underlying structure.

Stacks only allow Push, Pop, and Get from the "top" of the stack, and Queues only allow Push from the back, and Pop and Get from the front.

These data structures exist to help implement specific purposes - such as a queue to keep track of data received, line them up, and process the items in the list, moving from front to back.


Queues are a type of structure that only allows new items to be added to the end of the queue, and only allows items to be removed at the beginning of the queue. It is commonly called FIFO: First In First Out. A queue is basically any line you have to stand in at a store.

Queue operationcalls function from List/Vector


The Stack is LIFO: Last In First Out. The stack can be visualized as a can of Pringles chips, where you only have access to whatever is on the top of the internal stack of chips.

Stack operationcalls function from List/Vector

Stack example: Screen navigation

Main Menu

View stack:

Stack example: Undo

Input stack:

Queue example: Processing items

Current item:

Work queue:

Stack and Queue functionality

If I added the same information about functionality here as I have in the book, pretty soon the data between both sources would go out of sync and I don't want to have to maintain two separate resources on this. Therefore, it's time to pop over to the book. ;)

➡️➡️ https://moosadee.gitlab.io/courses/ ⬅️⬅️

Example code and additional resources