Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

priority queue c++

priority_queue<int> pq;//this works like rank (e.g: rank=1 > rank=2)
//the lower the rank the higher is the priority
pq.push(3);
cout<<pq.top()<<endl;
cout<<pq.size()<<endl;
pq.pop();
if(pq.empty()){
  cout<<"priority queue is empty"<<endl;
}

priority_queue<int, vector<int>, greater<int>> pqr;
//this is the reverse priority queue
//this works like score the higher the score the more is it's priority
pqr.push(1);
pqr.push(4);
cout<<pqr.top()<<endl;
pqr.pop();
cout<<pqr.size()<<endl;
if(!pqr.empty()){
  cout<<"the priority queue is not empty"<<endl;
}
 
PREVIOUS NEXT
Tagged: #priority #queue
ADD COMMENT
Topic
Name
9+3 =