1.bubble sort using go

2.test edited
This commit is contained in:
chenshilong 2022-12-07 18:38:12 +08:00
parent 10b1216675
commit 8643efece9

View File

@ -10,31 +10,11 @@ import (
) )
func TestBubbleSort(t *testing.T) { func TestBubbleSort(t *testing.T) {
var ( nums := []int{4, 1, 3, 1, 5, 2}
arr = []int{5, 4, 3, 2, 1} bubbleSort(nums)
) fmt.Println("冒泡排序完成后 nums = ", nums)
fmt.Println("冒泡排序前的数组:", arr)
bubbleSort(arr)
for i := 1; i < len(arr); i++ {
if arr[i] < arr[i-1] {
t.Errorf("排序不正确")
break
}
}
fmt.Println("冒泡排序后的数组:", arr)
}
func TestBubbleSortWithFlag(t *testing.T) { nums1 := []int{4, 1, 3, 1, 5, 2}
var ( bubbleSortWithFlag(nums1)
arr = []int{5, 4, 3, 2, 1} fmt.Println("冒泡排序完成后 nums1 = ", nums)
)
fmt.Println("冒泡排序前的数组:", arr)
bubbleSortWithFlag(arr)
for i := 1; i < len(arr); i++ {
if arr[i] < arr[i-1] {
t.Errorf("排序不正确")
break
}
}
fmt.Println("冒泡排序后的数组:", arr)
} }