zoukankan      html  css  js  c++  java
  • .NET 6.0 —— PriorityQueue

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

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

    优先队列

    PriorityQueue<TElement, TPriority>(System.Collections.Generic) 是一个新集合,可以添加具有值和优先级的新项目。在出队时,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

     
  • 相关阅读:
    isalnum()方法
    index()方法
    find()方法
    expandtabs()方法
    endswith()方法
    encode()方法
    bytes.decode()方法
    count()方法
    center()方法
    capitalize()方法
  • 原文地址:https://www.cnblogs.com/panpanwelcome/p/15785205.html
Copyright © 2011-2022 走看看