Go语言之直接选择排序
2021-05-11 23:31
标签:selection 语言 nbsp sort 排序 span func cti class Go语言之直接选择排序 标签:selection 语言 nbsp sort 排序 span func cti class 原文地址:https://www.cnblogs.com/beanbag/p/13149515.html/*
直接选择排序
*/
func straightSelectionSorter(array []int) {
for i := 0; i {
k := i
for j := i + 1; j {
if array[k] > array[j] {
k = j
}
}
if k != i {
//交换k和i上面的值
temp := array[k]
array[k] = array[i]
array[i] = temp
}
}
}
func main() {
var arr = []int{94, 12, 34, 76, 26, 9, 0, 37, 55, 76, 37, 5, 68, 83, 90, 37, 12, 65, 76, 49}
straightSelectionSorter(arr)
fmt.Println(arr)
}