go_排序算法_奇偶排序
2021-06-10 00:02
标签:print 偶数 turn false pack for package sort pac 核心思想:奇数位和偶数位的数据交替比较,最终实现排序 代码实现: import "fmt" func IsSort(arr []int) []int { } func main() { go_排序算法_奇偶排序 标签:print 偶数 turn false pack for package sort pac 原文地址:https://www.cnblogs.com/ydg-941020/p/14484662.html奇偶排序
package main
flag := false
if len(arr)
return arr
}
for flag == false {
flag = true
for i := 0; i
if arr[i] > arr[i+1] {
arr[i], arr[i+1] = arr[i+1], arr[i]
flag = false
}
} for i := 1; i arr[i+1] {
arr[i], arr[i+1] = arr[i+1], arr[i]
flag = false
}
}
}
return arr
arr := []int{5, 555, 4, 7, 5, -7, 99}
fmt.Println(IsSort(arr))
}