Last active
November 5, 2017 04:02
-
-
Save tacigar/df02710d5ba166caabe908c2d4b4da7c 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
let rec partition p = function | |
| [] -> [], [] | |
| hd :: tl -> | |
let ll, rl = partition p tl in | |
if p hd then | |
hd :: ll, rl | |
else | |
ll, hd :: rl | |
let rec quick_sort = function | |
| [] -> [] | |
| [x] -> [x] | |
| pivot :: rest -> | |
let ll, rl = partition (fun x -> x < pivot) rest in | |
(quick_sort ll) @ [pivot] @ (quick_sort rl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment