【发布时间】:2011-03-16 17:33:35
【问题描述】:
我正在寻找 C++ 中 有界优先级队列 抽象的免费软件实现。基本上,我需要一个行为类似于 std::priority_queue 的数据结构,但在任何时候都最多保存“最佳”n 个元素。
例子:
std::vector<int> items; // many many input items
bounded_priority_queue<int> smallest_items(5);
for(vector<int>::const_iterator it=items.begin(); it!=items.end(); it++) {
smallest_items.push(*it);
}
// now smallest_items holds the 5 smallest integers from the input vector
有谁知道这种事情的良好实施?有经验吗?
【问题讨论】:
-
我认为这在stackoverflow.com/questions/2933758/…中有所涉及
-
唉,购物问题永远不会不烂。
标签: c++ stl priority-queue