菜鸟算法
冒泡排序:
func BubbleSorter(array *[]int) {
fmt.Println("BubbleSorter Start ", *array)
len := len(*array)
for i := 0; i < len; i++ {
for j := 0; j < len-i-1; j++ {
if (*array)[j] > (*array)[j+1] {
(*array)[j], (*array)[j+1] = (*array)[j+1], (*array)[j]
}
}
}
fmt.Println("BubbleSorter End ", *array)
}

时间复杂度:O(N^2)
网友评论