1、 Queue<Character> que = new PriorityQueue( new Comparator<Character>() { public int compare(Character e1,Character e2) { return e2 - e1;///重载优先级使其变为大根堆 } }); 2、 class Item{ public Item(Character character, Integer count) { this.character = character; this.count = count; } private Character character; private int count; } //lamda表达式 PriorityQueue<Item> priorityQueue = new PriorityQueue<>((item1,item2)->item2.count-item1.count);
Java中的几种优先队列的比较函数的写法
猜你喜欢
转载自www.cnblogs.com/z2529827226/p/11722632.html
今日推荐
周排行