1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
package main import "fmt"
func main() { arr := []int{11, 2, 7, 11, 88, 91, 23, 14, 12, 33}
straight InsertSort (arr)
for i :=0 ; i < len(arr); i++ {
fmt. Println (arr[i])
}
} func straight InsertSort (unsorted []int) {
for i := 1; i < len(unsorted); i++ {
if unsorted[i-1] > unsorted[i] {
temp := unsorted[i]
var j int
for j = i - 1; j >= 0 && unsorted[j] > temp; j-- {
unsorted[j+1] = unsorted[j]
}
unsorted[j+1] = temp
}
}
}
|
本文转自yeleven 51CTO博客,原文链接:http://blog.51cto.com/11317783/1977408