Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

PQueue.h

Go to the documentation of this file.
00001 #ifndef __PQUEUE_H
00002 #define __PQUEUE_H
00003 
00004 #include <vector>
00005 #include <algorithm>
00006 
00007 //! Convenient priority queue implemented using the STL's heap algorithm
00008 template <class T>
00009 class PQueue {
00010 public:
00011   PQueue() : heap() {}
00012   void push(const T& obj);
00013   T pop ();
00014   bool isEmpty();
00015   
00016 protected:
00017   std::vector<T> heap;
00018 };
00019 
00020 template <class T>
00021 void PQueue<T>::push(const T& obj) {
00022   heap.push_back(obj);
00023   push_heap(heap.begin(), heap.end());
00024 }
00025 
00026 template <class T>
00027 T PQueue<T>::pop () {
00028   pop_heap(heap.begin(), heap.end());
00029   T returnVal = heap.back();
00030   heap.pop_back();
00031   return returnVal;
00032 }
00033 
00034 template <class T>
00035 bool PQueue<T>::isEmpty() { return (heap.size() == 0); }
00036 
00037 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:49 2016 by Doxygen 1.6.3