Skip to content

Instantly share code, notes, and snippets.

@dimatarelkin
Last active October 2, 2018 15:51
Show Gist options
  • Save dimatarelkin/4ed3e8f18a2e419f318887131771a474 to your computer and use it in GitHub Desktop.
Save dimatarelkin/4ed3e8f18a2e419f318887131771a474 to your computer and use it in GitHub Desktop.
Bubble, Merge & Quick sorts
//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