堆排序:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
java.util.ArraysHeapSort {
(String[] args) {
[] list = {}System..println(+ Arrays.(list))(list)System..println(+ Arrays.(list))}
([] list) {
(i = list./ i >= i--) {
(listilist.- )}
(i = list.-i>i--){
temp = list[]list[] = list[i]list[i] = temp(listi)}
}
([] listparentlength) {
temp = list[parent]child = parent * + (child < length) {
(child + < length && list[child + ] < list[child]){
child ++ }
(list[child] > list[parent]){
}
list[parent] = list[child]parent = childchild = * parent +}
list[parent] = temp}
}
|
本文转自里冲51CTO博客,原文链接: http://blog.51cto.com/coollast/1124311
,如需转载请自行联系原作者