Mar*_*ech 5 c++ stl priority-queue
我正在寻找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
Run Code Online (Sandbox Code Playgroud)
有谁知道这样的事情的良好实施?有经验吗?
| 归档时间: |
|
| 查看次数: |
1721 次 |
| 最近记录: |