Priority queue is a message with a priority value. It is an extension of the queue.
When you try to remove an item from the priority queue, the item with the highest attribute is removed first.
Let’s see how to set up a priority queue −
public class MyPriorityQueue <T> where T : IComparable <T> { }
Now let’s add an item. In the example below, the items are stored in info, which is a generic list.
public class MyPriorityQueue <T> where T : IComparable <T> { private List <T> info; public MyPriorityQueue() { this.info = new List <T>(); } }
The above is the detailed content of Priority Queue in C#. For more information, please follow other related articles on the PHP Chinese website!