Computer Science I / Stacks and Queues
Practice question · Multiple choice

Both a stack and a queue store items and hand them back one at a time. Why does reversing which end you remove from make one of them right for undo history and the other right for a print spooler?

Hints
  1. Undo should reverse the LAST thing you did. Printing should serve whoever waited longest.
  2. Both structures store the same items. Only the exit differs.
Show the answer

C. Because the removal order encodes a different relationship to time.

Why

The two differ in one decision, which end you remove from, and that decision encodes a policy about time. Last-in-first-out returns the most recent, which is precisely what undo means. Using a stack for a spooler would serve the newest job first, leaving a nine a.m. document unprinted all day. The choice is never about speed; both are constant time.

Read the lesson: Stacks and Queues →

Practise Stacks and Queues

The app has 7 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.

More questions on Stacks and Queues