Home  >  Article  >  Backend Development  >  Priority Queue in C#

Priority Queue in C#

王林
王林forward
2023-09-16 11:05:021468browse

C# 的优先级队列

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.

Example

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete