Created
June 11, 2014 21:58
-
-
Save vgrichina/0f0e71f4b30ba1c513c6 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
// Playground - noun: a place where people can play | |
import UIKit | |
let b = [1, 2, 3][1..2].filter { $0 < 3 } | |
let c = b + [5, 6] | |
func quicksort<T : Comparable>(arr : Array<T>) -> Array<T> { | |
if arr.count <= 1 { | |
return arr | |
} | |
let pivot = arr[0] | |
let tail = arr[1..arr.count] | |
let lesser = tail.filter { $0 < pivot } | |
let greater = tail.filter { $0 >= pivot } | |
return quicksort(lesser) + [pivot] + quicksort(greater) | |
} | |
//quicksort([3, 5, 2, 1]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment