Free implementation of "priority queue" in C ++

I am looking for a free implementation of limited priority abstraction software in C ++. Basically, I need a data structure that will behave exactly the same as std::priority_queue, but will always contain the "best" n elements.

Example:

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

Does anyone know of a good implementation of such a thing? Any experience with him?

+5
source share
2 answers

, , , , , . , Boost d_ary_heap_indirect, Boost.Graph( d_ary_heap.hpp). , Boost. , , , .

+1

std::vector functor/ std:: sort() ? , ,

0

All Articles