Created
March 28, 2012 02:58
-
-
Save jdpage/2223160 to your computer and use it in GitHub Desktop.
Quicksort in F#
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
open System | |
let rec sorted = function | |
| (x :: xs) -> | |
let left, right = List.partition (fun i -> i < x) xs | |
let sleft = sorted left | |
let sright = sorted right | |
sleft @ (x :: sright) | |
| [] -> [] | |
let rnd = new Random() | |
let l = [for i in [1 .. 100] -> rnd.Next(1, 1000)] | |
printfn "%A" l | |
printfn "%A" <| sorted l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment