Skip to content

Instantly share code, notes, and snippets.

@mitulmanish
Created July 22, 2016 10:05
Show Gist options
  • Save mitulmanish/bb5530f89d6af8d0edcd8369be22e7b5 to your computer and use it in GitHub Desktop.
Save mitulmanish/bb5530f89d6af8d0edcd8369be22e7b5 to your computer and use it in GitHub Desktop.
func bubbleSort(inout set: [Int]) -> [Int] {
for i in 0..<set.count {
var swapAvailable = false
for j in 0..<set.count-i-1 {
if set[j+1] < set[j] {
let smallest = set[j+1]
set[j+1] = set[j]
set[j] = smallest
swapAvailable = true
}
}
if !swapAvailable { return set }
swapAvailable = false
}
return set
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment