-
stl的优先级队列
添加时间:2013-7-30 点击量:#include <iostream>
#include <vector>
#include <queue>
using namespace std;
class Timer;
typedef Timer RTimer;
class Timer
{
public:
Timer():_interval(0),_expires_time(0){}
virtual ~Timer(){}
virtual void schedule_timer(int sec,int usec = 0)
{
}
virtual long expires_time()
{
return this->_expires_time;
}
virtual long interval_time()
{
return this->_interval;
}
public:
long _interval;
long _expires_time;
};
struct RTimerCmp
{
bool operator()(RTimer left,RTimer right)
{
if(left->_expires_time == right->_expires_time)
{
return right->_expires_time > left->_expires_time;
}
else
{
return left->_expires_time > right->_expires_time;
}
}
};
std::priority_queue<RTimer,std::vector<RTimer>,RTimerCmp > _rtime_queue;
int main()
{
Timer timer1;
timer1._expires_time = 1;
Timer timer2;
timer2._expires_time = 2;
Timer timer3;
timer3._expires_time = 3;
_rtime_queue.push(&timer1);
_rtime_queue.push(&timer3);
_rtime_queue.push(&timer2);
while(true)
{
if(_rtime_queue.size() <= 0)
{
break;
}
RTimer r = _rtime_queue.top();
cout << expire << r->_expires_time << endl;
_rtime_queue.pop();
}
return 0;
}:-),记录一下!
stl 容器 优先级队列 指针
我所有的自负皆来自我的自卑,所有的英雄气概都来自于我的软弱。嘴里振振有词是因为心里满是怀疑,深情是因为痛恨自己无情。这世界没有一件事情是虚空而生的,站在光里,背后就会有阴影,这深夜里一片寂静,是因为你还没有听见声音。—— 马良《坦白书》