多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
> 时间复杂度O(nlog(n)),辅助空间O(nlog(n)),不稳定 ```java public static <T extends Comparable> void heapSort(T[] a) { int n = a.length; for (int k = n / 2; k >= 1; k--) { sink(a, k, n); } while (n > 1) { swap(a, 1 - 1, (n--) - 1); sink(a, 1, n); } } private static <T extends Comparable> void sink(T[] pq, int k, int n) { while (2 * k <= n) { int j = 2 * k; if (j < n && less(pq[j - 1], pq[j])) { j++; } if (!less(pq[k - 1], pq[j - 1])) { break; } swap(pq, k - 1, j - 1); k = j; } } ```