Last active
August 29, 2015 14:02
-
-
Save kaandedeoglu/36123230d9524721cc60 to your computer and use it in GitHub Desktop.
QuickSort
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 qckSort<T: Comparable>(v: T[]) -> T[] { | |
switch v { | |
case []: | |
return [] | |
default: | |
let head = v[0] | |
var tail = v.copy() | |
tail.removeAtIndex(0) | |
return qckSort(tail.filter({$0 <= head})) + [head] + qckSort(tail.filter({$0 > head})) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment