//选择排序-升序
func minMax(array: inout [Int]) {
for i in (0..<array.count){
var k = i
for j in (k+1..<array.count){
if(array[k] > array[j]){
k = j
}
}
if(k != i){
let temp = array[k]
array[k] = array[i]
array[i] = temp
}
}
print(array)
}
var array = [8, -6, 2, 109, 3, 71]
minMax(array: &array)
swift3.0选择排序法
最新推荐文章于 2021-09-22 14:27:14 发布