简体   繁体   English

STL优先级队列构造函数

[英]STL priority Queue constructor

Why priority queue have that signature ? 为什么优先级队列具有该签名?

std::priority_queue<int, std::vector<int>, std::greater<int> > third;

For what need std::vector<int> ? 需要什么std::vector<int> If I, for example, need to store in queue only ints ? 例如,如果我仅需要将int存储在队列中?

These are the template arguments for priority_queue . 这些是priority_queue的模板参数。 The second one is the backing container used for storing the values and in this case you use vector (which is the default container). 第二个是用于存储值的后备容器,在这种情况下,您将使用vector(这是默认容器)。 In the example above it is passed so that you can change the default comparison predicate with std::greater (ie have a priority_queue where the smallest value is at the top). 在上面的示例中,它通过了,以便您可以使用std::greater更改默认比较谓词(即,具有priority_queue ,其中最小值位于顶部)。 Have a look at the class declaration here . 看看这里的类声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM