package main
import "fmt"
//功能:冒泡排序,从小到大排序
//入参:待排序数组
//返回值:排序好的数组
func BubbleSort(arr []int, length int)(sort[]int) {
for i := 0;i < length;i++ {
for j := 0;j < length - i - 1;j++ {
if arr[j] > arr[j+1] {
tmp := arr[j]
arr[j] = arr[j+1]
arr[j+1] = tmp
}
}
}
sort = arr
return sort
}
func main() {
arr := []int{1,5,3,8,4,2}
sortArr := BubbleSort(arr, 6)
for i := 0;i < len(sortArr);i++ {
fmt.Printf("%d ", sortArr[i])
}
}