【小技巧】【堆】【优先队列】优先队列初始化
生活随笔
收集整理的這篇文章主要介紹了
【小技巧】【堆】【优先队列】优先队列初始化
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
大小堆的建立(其他類比)
1.1 Map的小堆
1.2 Map的大堆
//b - a 大堆(后減前) //idea Comparator 自動生成 PriorityQueue<Integer> queue = new PriorityQueue<>(new Comparator<Integer>() {@Overridepublic int compare(Integer a, Integer b) {return map.get(b) -map.get(a);}});PriorityQueue<Map.Entry<Integer, Integer>> priorityQueue = new PriorityQueue<>(new Comparator<Map.Entry<Integer, Integer>>() {@Overridepublic int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {return o2.getValue().compareTo(o1.getValue());}});1.3 一個類 分開寫
// Customer 一個class 含id 7 初始化大小 Queue<Customer> customerPriorityQueue = new PriorityQueue<>(7, idComparator); //匿名Comparator實現public static Comparator<Customer> idComparator = new Comparator<Customer>(){@Overridepublic int compare(Customer c1, Customer c2) {return (int) (c1.getId() - c2.getId());}}; 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的【小技巧】【堆】【优先队列】优先队列初始化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UVA 1156 - Pixel Shu
- 下一篇: 怎么和产品沟通