package Sort
import (
"fmt"
"testing"
)
func BubbleSort(array []int) {
if array== nil || len(array)<2 {
return
}
for end:=len(array)-1;end>0;end-- {
for j:=0;j<end;j++{
if array[j]>array[j+1] {
Swap(array,j,j+1)
}
}
}
}
func TestBubbleSort(t *testing.T) {
arr := []int{230, 234, 43, 12, 2, 30,0, 23,230, 234, 43, 12, 2,30,0, 23}
BubbleSort(arr)
fmt.Println(arr)
}
//func swap(arr []int, i, j int) {
// tmp := arr[i]
// arr[i] = arr[j]
// arr[j] = tmp
//}
06-25
2万+
05-26
797
07-22
1693
01-28
2546
01-19
2193