diff --git a/notes/算法 - 排序.md b/notes/算法 - 排序.md index da0d046e..ed678c5a 100644 --- a/notes/算法 - 排序.md +++ b/notes/算法 - 排序.md @@ -363,6 +363,7 @@ public class ThreeWayQuickSort> extends QuickSort { ```java public T select(T[] nums, int k) { + shuffle(nums); int l = 0, h = nums.length - 1; while (h > l) { int j = partition(nums, l, h); @@ -397,6 +398,7 @@ public class Heap> { private T[] heap; private int N = 0; + // 容量固定为 maxN,插入超过 maxN 个元素时数组越界 public Heap(int maxN) { this.heap = (T[]) new Comparable[maxN + 1]; } @@ -471,6 +473,8 @@ public void insert(T v) { ```java public T delMax() { + if (isEmpty()) + throw new NoSuchElementException("堆为空"); T max = heap[1]; swap(1, N--); heap[N + 1] = null;