冒泡排序
var arr = [11,2,6,555,45,89,23,76,12,35,99,44,8,123,999]
func bubbleSort (inout arr: Array<Int> ) -> Array<Int> {
for i in 0..<arr.count {
for j in 0..<arr.count-1 - i {
if arr[j] > arr[j+1]{
let temp = arr[j]
arr[j] = arr[j+1]
arr[j+1] = temp
}
}
}
return arr
}
bubbleSort(&arr)
网友评论