冒泡排序
package main import ( "fmt" ) func main() { a := [...]int{1, 3, 6, 4, 8, 0, 6} fmt.Println(a) num := len(a) for i := 0; i < num; i++ { for j := i + 1; j < num; j++ { if a[i] < a[j] { temp := a[i] a[i] = a[j] a[j] = temp } } } fmt.Println(a) }
package main import ( "fmt" ) func main() { a := [...]int{1, 3, 6, 4, 8, 0, 6} fmt.Println(a) num := len(a) for i := 0; i < num; i++ { for j := i + 1; j < num; j++ { if a[i] < a[j] { temp := a[i] a[i] = a[j] a[j] = temp } } } fmt.Println(a) }