ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
> # 插入排序 ~~~ package main import "fmt" func insertionSort(arr []int) { n := len(arr) for i := 1; i < n; i++ { key := arr[i] j := i - 1 for ; j >= 0 && key < arr[j]; j-- { arr[j+1] = arr[j] } arr[j+1] = key } } func main() { arr := []int{64, 34, 25, 12, 22, 11, 90} fmt.Println("Before sorting:", arr) insertionSort(arr) fmt.Println("After sorting:", arr) } ~~~