优先级队列——实现二维数组排序

tech2024-11-08  6

PriorityQueue<Customer> queue = new PriorityQueue<>(); class Customer implements Comparable<Customer> { public int num; public int fee; public Customer(int num, int fee) { this.num = num; this.fee = fee; } // 重点,重写compareTo方法 // 此处 fee 降序排列 @Override public int compareTo(Customer o) { if(o.fee>this.fee){ return 1; }else if(o.fee <this.fee){ return -1; } return 0; } }
最新回复(0)