package main
import "fmt"
func BubbleSort(arr []int64) {
for range arr {
for index, v := range arr {
if index < len(arr)-1 && v > arr[index+1] {
arr[index+1], arr[index] = arr[index], arr[index+1]
}
}
}
}
func main() {
//切片本身是引用传递
a := []int64{1, 23, 4, 56, 6}
BubbleSort(a)
fmt.Println(a)
}
网友评论