Exam-style question
Try this first
A stack contains, from bottom to top, A, B, and C. What value is returned by peek, and what happens to the stack?.
- A.A is returned and removed
- B.B is returned and removed
- C.C is returned and remains in the stack
- D.C is returned and removed
Model answer
What a good answer should say
- C is returned and remains in the stack
Explanation
Why this works
C is the top element. Peek, also called top, returns the top value without removing it.
Common mistake
No common mistake is linked to this question yet.
