Skip to content

Instantly share code, notes, and snippets.

@volkanbicer
Last active November 11, 2017 16:39
Show Gist options
  • Save volkanbicer/0b0633415405217b170faae9f8cfc961 to your computer and use it in GitHub Desktop.
Save volkanbicer/0b0633415405217b170faae9f8cfc961 to your computer and use it in GitHub Desktop.
Selection sort for swift
func selectionSort(_ array: [Int]) -> [Int]{
var a = array
for i in 0..<a.count - 1{
var lowest = i
for j in i+1..<a.count{
if a[j] < a[lowest]{
lowest = j
}
}
if lowest != i{
(a[i], a[lowest]) = (a[lowest], a[i])
}
}
return a
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment