package main
import "fmt"
func main() {
arr := []int{7, 13, 4, 5, 8, 1, 11, 9}
fmt.Println("排序前", arr)
length := len(arr) - 1
for i := length; i >= 0; i-- {
for j := 0; j <= i - 1; j++ {
if arr[j] > arr[j+1] {
arr[j], arr[j+1] = arr[j+1], arr[j]
}
}
}
fmt.Println("排序后",arr)
}
排序前 [7 13 4 5 8 1 11 9]
排序后 [1 4 5 7 8 9 11 13]