多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
> # 插入排序 ~~~ 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) } ~~~