#include<iostream>
#include<string>
#include<string.h>
#include<queue>
using namespace std;
struct node
{
char str[100];
int cc, num, id;//num编号,id优先级
friend bool operator < ( node x, node y)
{
if(x.id == y.id)
return x.num > y.num;
else
return x.id > y.id;
}
};
int main()
{
node now;
char c[4];
int temp = 0;
priority_queue<node>q;
while(scanf("%s", c) != EOF)
{
if(!strcmp(c, "GET"))
{
if(q.empty())
printf("EMPTY QUEUE!\n");
else
{
now = q.top();
q.pop();
printf("%s %d\n", now.str, now.cc);
}
}
else
{
scanf("%s%d%d", now.str, &now.cc, &now.id);
now.num = ++temp;
q.push(now);
}
}
return 0;
}
hud 1509 Windows Message Queue 简单优先队列
最新推荐文章于 2019-08-09 19:37:00 发布
本文介绍了一个使用C++实现的优先级队列程序,该程序通过结构体定义节点,并利用优先级队列的数据结构特性来实现对节点的管理和操作。文章详细展示了如何根据节点的优先级和编号进行元素的添加和获取操作。

8010

被折叠的 条评论
为什么被折叠?



