swift语言编写冒泡排序代码
时间: 2023-02-20 19:54:35 浏览: 93
swift代码-string test
好的,下面是 Swift 语言实现的冒泡排序代码:
```
func bubbleSort(arr: [Int]) -> [Int] {
var result = arr
let count = result.count
for i in 0..<count {
for j in 0..<count - i - 1 {
if result[j] > result[j + 1] {
let temp = result[j]
result[j] = result[j + 1]
result[j + 1] = temp
}
}
}
return result
}
```
该代码实现了冒泡排序算法,将数组从小到大排序。
阅读全文