Last active
June 28, 2016 23:22
-
-
Save therealbnut/8a6feb83ef9cdcea4627190ef4f974b5 to your computer and use it in GitHub Desktop.
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
// Using XCode 7.3.1 (it's all I had at the time) | |
extension MutableCollectionType where Generator.Element: Comparable { | |
mutating func selectionSortInPlace() { | |
for currentIndex in self.startIndex ..< self.endIndex { | |
guard let (minIndex, minElement) = zip((currentIndex ..< self.endIndex), self.suffixFrom(currentIndex)) | |
.minElement({ lhs, rhs in (lhs.1 as! Generator.Element) < (rhs.1 as! Generator.Element) }) | |
else { | |
continue | |
} | |
self[minIndex] = self[currentIndex] | |
self[currentIndex] = minElement as! Generator.Element // swifty code finds compiler bugs | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment