Project: Overview
- Algorithms course
- Intermediate
- Lesson 45/80
- 4 min
Plan a mini app managing tasks with a stack and queue.
Project: Overview
In this project we build an undo system for a text editor. Stack, queue and state printing will accumulate.
Step 1: prepare empty stack. Step 2: add action. Step 3: undo. Step 4: print state.
Each lesson includes the previous solution; the code grows step by step.
Stack logic
A stack works with LIFO (last-in first-out) logic: the last added is the first removed. Ideal for an undo system.
Each action is pushed onto the stack. When undoing it is popped. The most recent action is undone first.
In Python a list is used: append for push, pop for pop.
Practice Empty stack
Write init_undo(). Return an empty list. Print [] with print(init_undo()).
Starter code
def init_undo():
# Empty undo stackSample solution
def init_undo():
# Empty undo stack
return []
print(init_undo())Expected output
[]
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Project: Overview: match the terms
| Term | Meaning |
|---|---|
Step 1 |
Empty stack |
Step 2 |
Push |
Step 3 |
Undo |
Step 4 |
2 Which data structure does the undo system use?
- Queue
- Stack Correct answer
- Tree
- Hash table
Explanation: Stack
3 Push operation
stack.____(action)
stack.append(action)
Explanation: append is right.