Stacks Preparation
Overview
We’ll start our exploration of ADTs with one of the simplest: the stack. The ability to simply place an item on a stack and remove items last-in, first-out can be used to elegantly solve many problems. Today, we’ll focus on how we can use the humble stack ADT.
Basic Learning Objectives
Before class, you should be able to:
- Explain the difference between an ADT and a data structure
- Explain what a stack is and how items are added and removed
- Define LIFO
- Explain the balanced parentheses problem
Advanced Learning Objectives
After class, you should be able to:
- Implement your own version of a stack
- Use a stack to solve a problem
Readings
Read the following in the online textbook Runestone:
- 1.5 Data Structures and ADTs
- 3.3 Stacks
- 3.4 The Stack ADT
- 3.6 Balanced Parentheses
- 3.7 Balanced Symbols
Checks
Submit answers to the follows on Moodle:
| “Teddy” |
| “Sam” |
| “Janine”|
-----------
- Given the stack above,
- What will calling
peek()
on this stack return? - What will the stack look like after calling
peek()
?
- What will calling
- Given the status of the stack after Step 1,
- What will calling
pop()
on this stack return? - What will the stack look like after calling
pop()
?
- What will calling
- Given the status of the stack after Step 2,
- What will calling
push(“Allison”)
on this stack return? - What will the stack look like after calling
push(“Allison”)
?
- What will calling