优先级队列排序对象不正确用户定义的比较

问题描述

我有一个类Customer,它有一个成员变量arrivalTime。我已经定义了一个吸气功能getArrivalTime()。我将Customer存储在优先级队列中,并定义了一个自定义谓词,如下所示:

class ArrivalQueueCompare
{
public:
    bool operator()(const Customer &a,const Customer &b)
    {
        return a.getArrivalTime() > b.getArrivalTime();
    }
};

优先级队列声明为:

std::priority_queue<Customer,std::vector<Customer>,ArrivalQueueCompare> arrivalQueue;

当我将四个Customer对象a0a1a2a3推入优先级队列时,到达时间为{{1 }},20050,优先级队列似乎按照30-a1-{{1}的顺序存储它们}-a0

根据我的谓词,顺序应为a2-a3-a1-a0,但是优先级队列会以其他方式存储它们。为什么会这样?

我已附上Xcode调试器屏幕上的屏幕截图作为证明:Screenshot 1 Screenshot 2 Screenshot 3 Screenshot 4

更新:

我正在从文件中读取行,并使用以下命令创建a3对象:

a2

Customer函数仅通过使用 while (std::getline(file,line)) { Customer newCustomer = createCustomerObject(line); arrivalQueue.push(newCustomer); } 初始化createCustomerObject()的成员变量来创建并返回Customer对象。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)