Last active
May 12, 2016 01:55
-
-
Save andybrackley/258106a1279d32b1d7c82962343867b0 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
module MergeSort = | |
let rec sort listToSort = | |
let rec merge lhs rhs = | |
match (lhs, rhs) with | |
| [], [] -> [] | |
| l, [] -> l | |
| [], r -> r | |
| x::xs, y::ys -> if x < y then x :: (merge xs rhs) else y :: (merge lhs ys) | |
match listToSort with | |
| [] -> [] | |
| [_] -> listToSort | |
| _ -> | |
let split = listToSort|> List.splitAt ( (listToSort |> List.length) / 2) | |
let sortedLhs = sort (fst split) | |
let sortedRhs = sort (snd split) | |
merge sortedLhs sortedRhs | |
module QuickSort = | |
let rec sort listToSort = | |
match listToSort with | |
| [] -> [] | |
| hd :: tail -> | |
let less, grt = tail |> List.partition ((>) hd) | |
sort less @ (hd :: sort grt) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment