codementor on Nostr: Learn: PriorityQueue for "smallest first" .NET has PriorityQueue<TElement, ...
Learn: PriorityQueue for "smallest first"
.NET has PriorityQueue<TElement, TPriority>. Dequeue always returns the item with the lowest priority value.
```csharp
var pq = new PriorityQueue<string, int>();
pq.Enqueue("low", 5); pq.Enqueue("urgent", 1); pq.Enqueue("mid", 3);
Console.WriteLine(pq.Dequeue());
```
It prints urgent. Use it for "top k" problems, merging k sorted lists, and Dijkstra's shortest path.
#tip · TIP-011
Published at
2026-10-26 17:37:56 UTCEvent JSON
{
"id": "50a55098e7c5835ff6104076f66dccff0b830308a44ecde719439ec7aacd3a69",
"pubkey": "e68a0856e90d9997b1f721e905249896412dd570399a987b2e8fd5e7fcfe2279",
"created_at": 1793036276,
"kind": 1,
"tags": [
[
"t",
"tip"
]
],
"content": "Learn: PriorityQueue for \"smallest first\"\n\n.NET has PriorityQueue\u003cTElement, TPriority\u003e. Dequeue always returns the item with the lowest priority value.\n\n```csharp\nvar pq = new PriorityQueue\u003cstring, int\u003e();\npq.Enqueue(\"low\", 5); pq.Enqueue(\"urgent\", 1); pq.Enqueue(\"mid\", 3);\nConsole.WriteLine(pq.Dequeue());\n```\n\nIt prints urgent. Use it for \"top k\" problems, merging k sorted lists, and Dijkstra's shortest path.\n\n#tip · TIP-011",
"sig": "17efe872a3f8c785a8eb128b2b82816b1e6fca6760d6014d2eb2248189106806e7eca39fdd13bc7289917251442d8e1cfbcdb462fb843c7a337f27d7cc7cb9bb"
}