Skip to content

Instantly share code, notes, and snippets.

@coreyd303
Created June 5, 2020 02:42
Embed
What would you like to do?
func bubbleSort(array: [Int]) -> [Int] {
var array = array
for i in 0..<array.count {
for j in 1..<array.count - i {
if array[j] < array[j - 1] {
array.swapAt(j, j - 1)
}
}
}
return array
}
var numbers = [Int]()
for _ in 0..<15 {
numbers.append(Int(arc4random_uniform(UInt32(1000))))
}
print(numbers)
print()
print(bubbleSort(array: numbers))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment