18 lines
329 B
Go
18 lines
329 B
Go
package sort
|
|
|
|
import (
|
|
"git.icoding.fun/yigencong/algorithm/go_solutions/utils"
|
|
)
|
|
|
|
// BubbleSort 冒泡排序算法
|
|
func BubbleSort(arr []int) {
|
|
n := len(arr)
|
|
for i := 0; i < n-1; i++ {
|
|
for j := 0; j < n-i-1; j++ {
|
|
if arr[j] > arr[j+1] {
|
|
utils.Swap(&arr[j], &arr[j+1]) // 使用 Swap 函数交换元素
|
|
}
|
|
}
|
|
}
|
|
}
|