Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. template<typename T> class Forest {
  2. public:
  3. // functions to do something with the heap,
  4. // but do not leak internals.
  5. void do_something(T const& x) {
  6. // pick a heap and add an element
  7. mHeaps[0].push(x);
  8. }
  9.  
  10. private:
  11. // simple wrapper around STL heap functions
  12. class Heap {
  13. public:
  14. void push(T const& x) {
  15. mData.push_back(x);
  16. std::push_heap(mData.begin(), mData.end());
  17. }
  18.  
  19. T pop() {
  20. std::pop_heap(mData.begin(), mData.end());
  21. T const tmp(mData.back());
  22. mData.pop_back();
  23. }
  24.  
  25. private:
  26. std::vector<T> mData;
  27. };
  28.  
  29. std::vector<Heap> mHeaps;
  30. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement