Files

7 lines
1.2 KiB
HTML

<!doctype html><html lang="en"><meta charset="utf-8"><title>Use a queue when order matters</title><h1>Use a queue when order matters</h1><p>15-minute session: read for 3 minutes, trace for 3, experiment for 7, and complete the check for 2. Spend longer whenever you need.</p><p>FIFO removes the oldest item first. Use a deque for a work queue instead of repeatedly removing index zero from a long list. Specify capacity and what happens when it fills. Test empty, one-item, and full states; an efficient structure still needs a correct policy.</p><p><strong>Practice and evidence:</strong> Predict the example or draw its state transitions. Change one assumption, test the boundary, and record the actual result. Explain what this small model does not establish about a production system.</p><pre><code class="language-python">from collections import deque
queue=deque([&quot;A&quot;,&quot;B&quot;])
print(queue.popleft())
queue.append(&quot;C&quot;)
print(list(queue))
</code></pre><p><strong>Expected result:</strong> <code>A
[&#x27;B&#x27;, &#x27;C&#x27;]</code></p><h3>Practice and evidence</h3><p>Keep three notes: your prediction, the actual result, and why they match or differ. The completion check grades understanding; the practice task builds skill.</p></html>