BeginnerCoder

Lesson 11 — Queues: round-robin scheduler

Queue in action: round-robin scheduling

Your computer runs many programs "at once" by giving each a short time slice in turn. That is round-robin: take the first job from the queue, run it for one slice, and if it still has work left, put it at the back of the queue. Repeat until the queue is empty.

person, items = line.popleft()
items -= 1
if items > 0:
    line.append((person, items))   # back of the line

Why it matters: fair sharing of CPU time, game turns and support tickets all use this queue pattern.

Want it another way?
Task

Write the "put it back" step: if the job has time left, append it to the back of the queue.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.