#include<iostream>
#include<queue>
#include<string>
using namespace std;
// イベントクラス
class Event{
public:
Event(string msg, int priority){
m_msg = msg;
m_priority = priority;
}
string m_msg;
int m_priority;
};
// 比較演算子
bool operator<( const Event& a, const Event& b ){
return a.m_priority < b.m_priority;
}
// 出力ストリーム
ostream& operator<<( ostream& os, const Event& event ){
return os << event.m_priority << " " << event.m_msg << endl;
}
void main(){
// 空のint型priority_queueを作る
priority_queue<Event, vector<Event>, less<Event> > pq;
pq.push( Event("火事だ!", 10) );
pq.push( Event("地震だ!", 9 ) );
pq.push( Event("電話です", 3) );
pq.push( Event("誰か来ました!", 4) );
pq.push( Event("メールです", 2) );
// priority_queueの中身を表示する
while( !pq.empty() ){
cout << pq.top() << ' ';
pq.pop();
}
cout << endl;
}
|