Skip to content

Instantly share code, notes, and snippets.

@trilliwon
Last active December 15, 2016 07:20
Show Gist options
  • Save trilliwon/012479ea56bafd32e468d2e028795492 to your computer and use it in GitHub Desktop.
Save trilliwon/012479ea56bafd32e468d2e028795492 to your computer and use it in GitHub Desktop.
Quicksort in Swift
import Foundation
func quicksort<T: Comparable>(array: [T]) -> [T] {
if array.count <= 1 { return array }
let pivot: T = array[array.count/2]
return quicksort(array: array.filter ({ $0 < pivot })) + array.filter ({ $0 == pivot }) + quicksort(array: array.filter ({ $0 > pivot }))
}
// http://www.slideshare.net/ssuserae280e/quicksort-in-swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment