CKTIS / C#
System.Collections.Generic.PriorityQueue: practical reference
System.Collections.Generic.PriorityQueue: practical reference: PriorityQueue<TElement,TPriority> removes the element with the lowest priority according to its priority comparer.
Version: .NET API; verified on .NET 10.0.14
Syntax
System.Collections.Generic.PriorityQueue /* select a documented member or constructor */PriorityQueue<TElement,TPriority> removes the element with the lowest priority according to its priority comparer.
Use it in schedulers and graph algorithms where priority, rather than insertion order, selects the next item.
Equal priorities do not guarantee stable FIFO order, and the element and its priority are stored separately.
Dequeue on an empty queue throws InvalidOperationException, while TryDequeue returns false.
The complete program actually uses System.Collections.Generic.PriorityQueue; its exact expected stdout is first.
Examples
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
var queue = new PriorityQueue<string, int>();
queue.Enqueue("later", 2);
queue.Enqueue("first", 1);
Console.WriteLine(queue.Dequeue());
Result
first
The complete program actually uses `System.Collections.Generic.PriorityQueue`; its exact expected stdout is `first`.