package main
import (
"fmt"
)
func InsertionSort(array [6]int, n int) {
var i, j int
var tmp int
for i = 1; i < n; i++ {
tmp = array[i]
for j = i; j > 0 && array[j-1] > tmp; j-- {
array[j] = array[j-1]
}
array[j] = tmp
}
fmt.Println(array)
}
func main() {
a := [...]int{34, 8, 64, 51, 32, 21}
fmt.Println(a)
num := len(a)
InsertionSort(a, num)
}
import (
"fmt"
)
func InsertionSort(array [6]int, n int) {
var i, j int
var tmp int
for i = 1; i < n; i++ {
tmp = array[i]
for j = i; j > 0 && array[j-1] > tmp; j-- {
array[j] = array[j-1]
}
array[j] = tmp
}
fmt.Println(array)
}
func main() {
a := [...]int{34, 8, 64, 51, 32, 21}
fmt.Println(a)
num := len(a)
InsertionSort(a, num)
}
有疑问加站长微信联系(非本文作者)