Address:
Click to open the link
Priority queue, note that there is one in it. If the priorities are equal, they are arranged in the order of appearance.
Code:
#include<iostream> #include<cstdio> #include<string.h> #include<stack> #include<queue> #include<queue> using namespace std ; #define MAX 400 struct Node{ char num[MAX] ; int by; int ranks ; int priority; friend bool operator <(Node a ,Node b ){ if(a.priority==b.priority) return a.ranks>b.ranks; else return a.priority>b.priority; } }; priority_queue<Node> qe; int main(){ char req[15],msg[15],par,priority; int index = 1 ; while(scanf("%s",&req)!=EOF) { if(strcmp(req,"GET")==0) { if(qe.empty()) { printf("EMPTY QUEUE!\n"); }else { Node tp = qe.top(); qe.pop(); printf("%s %d\n",tp.num,tp.par); } }else { Node tp; scanf("%s%d%d",&tp.num,&tp.par,&tp.priority); tp.ranks = index++; qe.push(tp); } } }