Skip to content

Instantly share code, notes, and snippets.

@coreyd303
Created June 5, 2020 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreyd303/e2105720979491dfba5cb79420bade8e to your computer and use it in GitHub Desktop.
Save coreyd303/e2105720979491dfba5cb79420bade8e to your computer and use it in GitHub Desktop.
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