KrisLibrary  1.0.0
priority_queue2.h
1 #ifndef PRIORITY_QUEUE_2_H
2 #define PRIORITY_QUEUE_2_H
3 
4 #include <vector>
5 
6 namespace std {
7 
13 template <class T,class Cmp=less<T> >
14 class priority_queue2 : private vector<T>
15 {
16  private:
18  typedef vector<T> ParentT;
19  Cmp compareObject;
20 
21  public:
22  typedef T value_type;
23  typedef Cmp value_compare;
24  typedef typename vector<T>::const_iterator const_iterator;
25  typedef typename vector<T>::const_reverse_iterator const_reverse_iterator;
26 
27  priority_queue2() {}
28  priority_queue2(const MyT& other) :ParentT(other) {}
29 
30  bool empty() const { return ParentT::empty(); }
31  void clear() { ParentT::clear(); }
32  const T& top() const { return ParentT::front(); }
33  const T& front() const { return ParentT::front(); }
34  const T& back() const { return ParentT::back(); }
35  void push(const T& obj) { ParentT::push_back(obj); push_heap(ParentT::begin(),ParentT::end(),compareObject); }
36  void pop() { pop_heap(ParentT::begin(),ParentT::end(),compareObject); ParentT::resize(ParentT::size()-1); }
37  const_iterator begin() const { return ParentT::begin(); }
38  const_iterator end() const { return ParentT::end(); }
39 
40  void swap(MyT& other) { swap((ParentT&)*this,other); }
41 };
42 
43 template <class T,class Cmp>
45 {
46  a.swap(b);
47 }
48 
49 } //namespace std
50 
51 #endif
Definition: rayprimitives.h:132
A better priority queue class than the STL version.
Definition: priority_queue2.h:14