package main
import (
"fmt"
)
func main() {
var arr []int
arr = []int{3, 4, 9, 6, 7, 1, 2}
res := iSort(arr)
fmt.Println(res)
}
func iSort(arr []int) []int {
var tmp int
count := len(arr)
for i := 1; i < count; i++ {
for j := i; j > 0 ; j-- {
if arr[j-1] > arr[j] {
tmp = arr[j-1]
arr[j-1] = arr[j]
arr[j] = tmp
}else {
break
}
}
}
return arr
}
有疑问加站长微信联系(非本文作者)