package main import ( "fmt" ) var ( array = []int{3, 6, 1, 8, 5} ) func main() { for _, v := range sort(array) { fmt.Println(v) } } func sort(array []int) []int { 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] } } } return array }
有疑问加站长微信联系(非本文作者)