Workstation topics · Data structures in plain words

Lesson 2 of 3 · about 20 minutes

Queues and stacks: who goes next?

🏠The everyday picture

At a railway ticket counter, the first person to join the queue is the first served. In a canteen, clean plates are put on top of a stack, and the next person takes the top plate: the last one put down is the first one used. Two simple rules, and programs use both all the time.

📘What it really is

Both keep things fair and predictable: nobody jumps the queue, and Undo always takes back the latest change first.

📝A worked example

Sharma Textiles packs online orders in the order they're paid:

queue: [order 101, order 102, order 103]
new order 104 arrives  → added at the back: [101, 102, 103, 104]
packer takes next      → 101 comes off the front: [102, 103, 104]

Priya types three changes in a document: adds a title, makes it bold, changes the colour. She presses Undo:

stack of changes: [title, bold, colour]   ← colour is on top
Undo  → takes "colour" off the top: the colour change is undone first
Undo  → takes "bold" off next

🖱️Try it

Look around today for one queue and one stack (a bus queue, a pile of letters on a desk, a stack of chapatis). For each, ask: is the newest one handled first, or the oldest? Then think of one app feature that works the same way.

✅Quick check

Customers call a helpline and wait for the next free person. Queue or stack?

Show the answer

A queue. The person who has waited longest should be answered first: first in, first out.

You press Undo three times. Which change is undone first?

Show the answer

The most recent one. Undo works like a stack: last in, first out.

🧩Check yourself

Tap an answer to see why every option is right or wrong. There's no score and nothing is saved, so try as often as you like.

1. A printer receives three documents: a bill, then a letter, then a photo. Which prints first?

2. Which of these works like a stack?

3. An online shop gets 300 orders in a festival sale. Packing them newest first would mean some early buyers wait for days. Which structure should the packing list use?

← PreviousLists: things in order
ProLearners Assist