Sorting PriorityQueue

前端 未结 3 762
难免孤独
难免孤独 2020-12-18 08:50

I am having a problem with PriorityQueues, as I am lead to believe it orders on priority however I am not sure what the priority is (I mean what the value is and where it co

3条回答
  •  臣服心动
    2020-12-18 09:35

    Instead of Comparator just use Comparable interface.

    Your Flight class should implement Comparable interface. Then you need to override the compareTo() method. In that method you can add your own logic for sorting based on the property you need.

    Just like this way:

    @Override
    public int compareTo(Object obj) {
        // TODO Auto-generated method stub
        Flight f = (Flight)obj;
        if(this.a 

提交回复
热议问题