1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
func simpleSelectionSort(unsorted [] int , n int ) {
var key, temp int
for i: = 0 ; i<n; i + + {
key = selectMiniKey(unsorted, n, i)
if key! = i {
temp = unsorted[i]
unsorted[i] = unsorted[key]
unsorted[key] = temp
}
}
} func selectMiniKey(a [] int , n int , i int ) int {
k: = i
for j : = i + 1 ; j<n; j + + {
if a[k] > a[j] {
k = j
}
}
return k
} |
本文转自yeleven 51CTO博客,原文链接:http://blog.51cto.com/11317783/1978033