priority queue code example
Example 1: python priority queue
from queue import PriorityQueue
class PqElement(object):
def __init__(self, value: int):
self.val = value
def __lt__(self, other):
"""self < obj."""
return self.val > other.val
def __repr__(self):
return f'PQE:{self.val}'
pq = PriorityQueue()
pq.put(PqElement(v))
topValue = pq.get()
topValue = pq.queue[0].val
Example 2: priority_queue
std::priority_queue<int, std::vector<int>, std::greater<int>>
Example 3: priority queue stl
using namespace std;
int main()
{
priority_queue<int>pq;
int n=5;
while(n--)
{
int val;
cout<<"enter the value you want to insert:"<<endl;
cin>>val;
pq.push(val);
}
priority_queue<int>p;
p.push(100);
p.push(1000);
p.push(3000);
p.push(5000);
pq.swap(p);
while(!pq.empty())
{
cout<<pq.top()<<" ";
pq.pop();
}
return 0;
}
Example 4: priority
Defect priority is the amount of urgency
to fixing that defect. Has fast bug has
to be fixed. We were discussing in grooming meeting.
Developers and PO determines the level of priority