https://www.zhihu.com/question/449756804

 

作者:醉书生
链接:https://www.zhihu.com/question/449756804/answer/2219422015
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

优先队列

新集合,可以添加具有值和优先级的新项目。在出队时,PriorityQueue 返回具有最低优先级值的元素。您可以将这个新集合视为类似于但每个入队元素都有一个影响出队行为的优先级值。Queue<T>

以下示例演示了.PriorityQueue<string, int>

// creates a priority queue of strings with integer priorities
var pq = new PriorityQueue<string, int>();

// enqueue elements with associated priorities
pq.Enqueue("A", 3);
pq.Enqueue("B", 1);
pq.Enqueue("C", 2);
pq.Enqueue("D", 3);

pq.Dequeue(); // returns "B"
pq.Dequeue(); // returns "C"
pq.Dequeue(); // either "A" or "D", stability is not guaranteed.

Patryk Golebiowski。

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2021-10-18
  • 2021-05-22
猜你喜欢
  • 2021-07-13
  • 2021-06-02
  • 2021-10-08
  • 2021-06-13
  • 2022-12-23
相关资源
相似解决方案