Created
June 5, 2020 02:42
-
-
Save coreyd303/e2105720979491dfba5cb79420bade8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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