I have declared std::priority_queue like this.
priority_queue < Aircraft, vector<Aircraft>, less<Aircraft> > *q;
And I overloaded the less operator like this.
bool Aircraft::operator<(const Aircraft &rhs) const
{
return (m_dep_time < rhs.m_dep_time);
}
I printed out the priority queue and I was getting element in decreasing order (the largest dep_time first). I had to change m_dep_time < rhs.m_dep_time to m_dep_time > rhs.m_dep_time and it worked. I was able to get the lowest dep_time as I intended.
I thought in logically using m_dep_time < rhs.m_dep_time was right instead of m_dep_time > rhs.m_dep_time to get an element from the queue in increasing order, the lowest value first.
Could you explain what I am missing?
Check out this reference. By default, the top element is the largest element. If you want opposite behavior, you must use different comparison function, just as you’ve done.