Last active
November 11, 2017 16:39
-
-
Save volkanbicer/0b0633415405217b170faae9f8cfc961 to your computer and use it in GitHub Desktop.
Selection sort for swift
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
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