您的位置:首页 > 产品设计 > UI/UE

windows 消息队列

2014-05-12 15:56 288 查看
#include<iostream>
#include<queue>
#include<string>
using namespace std;
struct Message
{
string msg;
int priority;
};

struct Cmp
{
bool operator()(Message const &msg_a,Message const &msg_b)
{
return msg_a.priority>msg_b.priority;
}
};

int main()
{
priority_queue<Message,vector<Message>,Cmp> msg_queue;
int n;
cin>>n;
for(int i=0;i<n;++i)
{
string tmp;
cin>>tmp;
if(tmp=="PUT")
{
Message msg_tmp;
cin>>msg_tmp.msg>>msg_tmp.priority;
msg_queue.push(msg_tmp);
}
else
{
if(!msg_queue.empty())
{
cout<<msg_queue.top().msg<<endl;
msg_queue.pop();
}
else
{
cout<<"EMPTY QUEUE!"<<endl;
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息