堆排序的Java实现

package sunbufu.sort; /** * 堆排序 * * 0 * 1 2 * 3 4 5 6 * * 在二叉树中: * 因为 * 根节点下标=左节点下标-1/2 * 根节点下标=右节点下标-2/2 * 所以 * 左节点下标=根节点下标*2+1 * 右节点下标=根节点下标*2+2 * * @author 孙不服 * */ public class HeapSort { public static void main(String[] args) { HeapSort heapSort = new HeapSort(); int[] data = { 3, 5, 8, 9, 1, 2 }; heapSort.data = data; heapSort.buildHeap(); for (int i = 0; i < data....

June 6, 2018 · 2 min · sunbufu