You push 4, push 7, pop, then push 9. What sits on top?
What is the stack rule?
- First in, first out
- Last in, first out: the top is the only value within reach
- Any item can leave at any time
In Python, how do you peek at the top of a stack list without removing it?
- Index minus one
- Pop twice
- Delete the list
Why does an editor undo stack pop the newest change first?
- That is exactly last in, first out applied to history
- Oldest work matters least
- Stacks cannot hold old changes
What should popping an empty stack do?
- Silently return garbage
- Signal an error or refuse clearly, as decided upfront
- Return the oldest value
In bracket matching, leftover opening brackets on the stack mean the nesting is fine.
Circle one: True False
A student uses a stack for a print queue and wonders why jobs print newest first. What is the error?
- Stacks reverse arrival order, so a queue is the right tool for arrival order
- Stacks cannot hold documents
- Printers cannot use any data structure
Push A, push B, pop, push C, pop, pop. What order do values come off?
- A, then B, then C
- C, then B, then A
- B, then C, then A