Last active
October 2, 2018 15:51
-
-
Save dimatarelkin/4ed3e8f18a2e419f318887131771a474 to your computer and use it in GitHub Desktop.
Bubble, Merge & Quick sorts
This file contains 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
//bubble sort | |
func bubbleSort (unsortedArray array: [Int]) -> [Int] { | |
var iteration = 0 | |
var newArray = array | |
while iteration < newArray.count - 1 { | |
var i = 0 | |
while i < newArray.count - 1 { | |
if newArray[i] > newArray[i+1] { | |
newArray[i..<i+2] = [array3[i+1], array3[i]] | |
} | |
i+=1 | |
} | |
iteration+=1 | |
} | |
return newArray | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment