Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T> class Forest {
- public:
- // functions to do something with the heap,
- // but do not leak internals.
- void do_something(T const& x) {
- // pick a heap and add an element
- mHeaps[0].push(x);
- }
- private:
- // simple wrapper around STL heap functions
- class Heap {
- public:
- void push(T const& x) {
- mData.push_back(x);
- std::push_heap(mData.begin(), mData.end());
- }
- T pop() {
- std::pop_heap(mData.begin(), mData.end());
- T const tmp(mData.back());
- mData.pop_back();
- }
- private:
- std::vector<T> mData;
- };
- std::vector<Heap> mHeaps;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement