The sort () function of the CMP is a function, the Priority_queue CMP is a class, the specific wording is:
struct Node { int I,j;} node[ 200 ]; struct cmp { bool operator () (Node A,node b) { if (A.i==B.I) return a.j<b.j; /// j Ascending return a.i<b.i; /// i Ascending <Node,vector<Node>,cmp> re;
#include <iostream>#include<queue>using namespaceStd;typedefstruct { intId///User ID intTime///The time of the next occurrence intPeriod///time interval} Register;///to define a comparison function for a priority queuestructCMP {BOOL operator() (Register A,register b) {if(a.time==b.time)returna.id>b.id;///Sorted by ID in ascending order when time is equal returna.time>b.time;///in ascending order of time, to be the smallest heap }};intMain () {///define the priority queue, first to the smallest arrival time, and in ascending order by ID when equalpriority_queue<register,vector<register>,cmp >re; stringcmd///Command intId///Define ID intPeriod///defining the time interval intCount///define the number of output bars while(true) {cin>>cmd; if(Cmd.compare ("#")==0) Break; CIN>>id>>period; Register R; R.id=ID; R.period=period; R.time=period; Re.push (R); } CIN>>count; while(count--) {Register reg=Re.top (); cout<<reg.id<<Endl; Reg.time+=Reg.period; Re.pop (); Re.push (REG); } return 0;}
View Code
Priority Queue (Priority_queue) for Cmp,poj (2051)