modify code

master
algorithmzuo 4 years ago
parent fdab79726d
commit d6570a1f53

@ -42,11 +42,6 @@ public class Code02_Heap {
return ans; return ans;
} }
// 新加进来的数现在停在了index位置请依次往上移动 // 新加进来的数现在停在了index位置请依次往上移动
// 移动到0位置或者干不掉自己的父亲了 // 移动到0位置或者干不掉自己的父亲了
private void heapInsert(int[] arr, int index) { private void heapInsert(int[] arr, int index) {
@ -124,8 +119,7 @@ public class Code02_Heap {
} }
public static class MyComparator implements Comparator<Integer> {
public static class MyComparator implements Comparator<Integer>{
@Override @Override
public int compare(Integer o1, Integer o2) { public int compare(Integer o1, Integer o2) {
@ -135,6 +129,7 @@ public class Code02_Heap {
} }
public static void main(String[] args) { public static void main(String[] args) {
// 小根堆 // 小根堆
PriorityQueue<Integer> heap = new PriorityQueue<>(new MyComparator()); PriorityQueue<Integer> heap = new PriorityQueue<>(new MyComparator());
heap.add(5); heap.add(5);
@ -150,16 +145,10 @@ public class Code02_Heap {
heap.add(7); heap.add(7);
heap.add(0); heap.add(0);
System.out.println(heap.peek()); System.out.println(heap.peek());
while(!heap.isEmpty()) { while (!heap.isEmpty()) {
System.out.println(heap.poll()); System.out.println(heap.poll());
} }
int value = 1000; int value = 1000;
int limit = 100; int limit = 100;
int testTimes = 1000000; int testTimes = 1000000;

Loading…
Cancel
Save