Go语言 之数组冒泡排序
package main import ( "fmt" ) func main() { var arr [10]int = [10]int{9, 8, 7, 6, 5, 4, 3, 2, 1, 0} var temp int for i := 0; i < len(arr)-1; i++ { for j := 0; j < len(arr)-1-i; j++ { if arr[j] > arr[j+1] { temp = arr[j] arr[j] = arr[j+1] arr[j+1] = temp } } } fmt.Println(arr) }