1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package main
import "fmt"
func SelectSort(data []int) {
length := len(data)
for i := 0; i < length; i++ {
tmp := data[i]
flag := i
for j := i + 1; j < length; j++ {
if data[j] < tmp {
tmp = data[j]
flag = j
}
}
if flag != i {
data[flag] = data[i]
data[i] = tmp
}
fmt.Println(data) //为了看具体排序的过程
}
}
func main() {
data := []int{44, 38, 65, 97, 76, 14, 27, 48}
SelectSort(data)
fmt.Println(data)
}
|