寻路基本工具类定义 PriorityQueue.h

 1 #ifndef __PRIORITYQUEUE__H
 2 #define __PRIORITYQUEUE__H
 3 
 4 #include <deque>
 5 
 6 template<typename T, typename Pr = std::less<T>, typename Container = std::deque<T> >
 7 class PriorityQueue
 8 {
 9 public:
10     bool empty() const
11     {
12         return (m_container.empty());
13     }
14 
15     unsigned int size() const
16     {
17         return (m_container.size());
18     }
19 
20     const T top() const
21     {
22         return m_container.front();
23     }
24 
25     T top()
26     {
27         return m_container.front();
28     }
29 
30     void push(const T &val)
31     {
32         Container::const_iterator iter = m_container.begin();
33         for(; iter != m_container.end(); ++iter)
34         {
35             if(!m_cmp(*iter, val))
36             {
37                 break;
38             }
39         }
40         m_container.insert(iter, val);
41     }
42 
43     void pop()
44     {
45         m_container.pop_front();
46     }
47 
48     void remove(const T &val)
49     {
50         Container::iterator iter;
51         for(iter = m_container.begin(); iter != m_container.end(); ++iter)
52         {
53             if((*iter) == val)
54             {
55                 m_container.erase(iter);
56                 break;
57             }
58         }
59     }
60 private:
61     Container   m_container;
62     Pr          m_cmp;
63 };
64 
65 #endif

 

posted @ 2013-11-23 01:21  liusijian  阅读(285)  评论(0编辑  收藏  举报