Skip to content

Instantly share code, notes, and snippets.

@dreampiggy dreampiggy/QuickSort.swift
Last active Jun 14, 2016

Embed
What would you like to do?
QuickSort in Swift
func quicksort<T: Comparable>(a: [T]) -> [T] {
if a.count <= 1 {
return a
} else {
let pivot = a[a.count/2]
let less = a.filter { $0 < pivot }
let equal = a.filter { $0 == pivot }
let greater = a.filter { $0 > pivot }
return quicksort(less) + equal + quicksort(greater)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.