Hello all,
I am looking for a solution on how to order a queue with priority.
Simply put, my requirements are:
- All elements must be FIFO. Whatever is added first must always come out first (unless there is a higher priority item first).
- Order by priority. Higher priority items will always come before lower ones.
std::priority_queue sounds perfectly for the job, but I can't for the life of me get the pop operation to maintain FIFO order among equal priorities. Does anyone have any idea on how to achieve this with priority_queue or some other container in some way or form?
Basically, what I have tried so far is this:
So far, neither of these approaches led to the queue maintaining FIFO order (perhaps I've implemented the operator wrong?).Code:bool operator > (const XQueueItem& other) { return (m_receipt.GetPriority() > other.m_receipt.GetPriority()); //if (m_receipt.GetPriority() > other.m_receipt.GetPriority()) // return true; //else if (m_receipt.GetPriority() < other.m_receipt.GetPriority()) // return false; //else //if (m_receipt.GetPriority() == other.m_receipt.GetPriority()) // return (m_slot > other.m_slot); }
Thanks.



LinkBack URL
About LinkBacks




riority_queue' is simply not guaranteed to be a stable priority queue. (They are more expensive and not necessary for a general purpose priority queue.)