冒泡法排序Go语言版
func BubbleSort(nums []int) { unsorted := true for unsorted { unsorted = false for i := len(nums) - 1; i > 0; i-- { if nums[i] < nums[i-1] { nums[i], nums[i-1] = nums[i-1], nums[i] unsorted = true } } } }
冒泡法排序Go语言版
func BubbleSort(nums []int) { unsorted := true for unsorted { unsorted = false for i := len(nums) - 1; i > 0; i-- { if nums[i] < nums[i-1] { nums[i], nums[i-1] = nums[i-1], nums[i] unsorted = true } } } }