2 Star 0 Fork 0

CS-IMIS-23/zc20172324

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
HeapSort.java 925 Bytes
一键复制 编辑 原始数据 按行查看 历史
zc20172324 提交于 7年前 . 书上代码
package chap12;
import chap10.LinkedBinaryTree;
/**c
* HeapSort sorts a given array of Comparable objects using a heap.
*
* @author Lewis and Chase
* @version 4.0
*/
public class HeapSort<T extends Comparable<T>> {
/**
* Sorts the specified array using a Heap
*
* @param data
* the data to be added to the heapsort
*/
public void HeapSort(T[] data) {
ArrayHeap<T> temp = new ArrayHeap<T>();
// copy the array into a heap
for (int i = 0; i < data.length; i++)
temp.addElement(data[i]);
// place the sorted elements back into the array
int count = data.length;
while (!(temp.isEmpty())) {
data[count] = temp.removeMax();
count--;
}
}
public static void main(String[] args) {
Integer[] data = {36,30,18,40,32,45,22,50};
HeapSort hs = new HeapSort<Integer>();
hs.HeapSort(data);
for(int i=0;i<data.length;i++){
System.out.print(data[i]+" ");
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/CS-IMIS-23/zc20172324.git
git@gitee.com:CS-IMIS-23/zc20172324.git
CS-IMIS-23
zc20172324
zc20172324
master

搜索帮助