Join Nostr
2026-10-26 17:37:56 UTC

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