codementor on Nostr: Learn: Queue<T>: first in, first out A queue gives items back in the order they came ...
Learn: Queue<T>: first in, first out
A queue gives items back in the order they came in. Enqueue adds at the back, Dequeue removes from the front, and Peek looks at the front without removing it.
```csharp
var q = new Queue<string>();
q.Enqueue("first"); q.Enqueue("second");
Console.WriteLine(q.Peek());
Console.WriteLine(q.Dequeue() + " " + q.Dequeue());
```
It prints first, then first second.
Queues are the tool for "handle in order of arrival": jobs, messages, and breadth-first search.
#sq006 · SQ-006-N
Published at
2026-10-26 19:08:02 UTCEvent JSON
{
"id": "1c6dbc6ee2169ad4334b6324b1d5dc6439094f60a71220880e3baeb44f8908d9",
"pubkey": "e68a0856e90d9997b1f721e905249896412dd570399a987b2e8fd5e7fcfe2279",
"created_at": 1793041682,
"kind": 1,
"tags": [
[
"t",
"sq006"
]
],
"content": "Learn: Queue\u003cT\u003e: first in, first out\n\nA queue gives items back in the order they came in. Enqueue adds at the back, Dequeue removes from the front, and Peek looks at the front without removing it.\n\n```csharp\nvar q = new Queue\u003cstring\u003e();\nq.Enqueue(\"first\"); q.Enqueue(\"second\");\nConsole.WriteLine(q.Peek());\nConsole.WriteLine(q.Dequeue() + \" \" + q.Dequeue());\n```\n\nIt prints first, then first second.\n\nQueues are the tool for \"handle in order of arrival\": jobs, messages, and breadth-first search.\n\n#sq006 · SQ-006-N",
"sig": "e4ef2917605f96ee08d0120158ec18018085aec2e5b60dbf6c90925dcd185648a28753598b746d42f5e751b1afa2da98b1a1412efad927e3e04e4c2e5e331c4f"
}