Go实现:
package main
import (
"fmt"
)
func main() {
var arr = []int{9, 4, 5, 2, 3, 8, 6, 7, 1, 0}
bubble_sort(arr)
fmt.Println(arr)
}
func bubble_sort(arr []int) []int {
for i := 0; i < len(arr); i++ {
for j := i + 1; j < len(arr); j++ {
tempI := arr[i]
tempJ := arr[j]
if tempI > tempJ {
arr[i] = tempJ
arr[j] = tempI
}
}
}
return arr
}