用go语言进行冒泡排序法
package main
import (
"fmt"
// "io/ioutil"
// "net/http"
// "reflect"
)
func main() {
var array []int
array = []int{2, 10, 45, 6, 7, 3, 5, 23}
for i := 0; i < len(array); i++ {
for j := 0; j < len(array)-i-1; j++ {
if array[j] < array[j+1] {
array[j], array[j+1] = array[j+1], array[j]
}
}
}
fmt.Println(array)
}
有疑问加站长微信联系(非本文作者)