Skip to content

Instantly share code, notes, and snippets.

@tacigar
Last active November 5, 2017 04:02
Show Gist options
  • Save tacigar/df02710d5ba166caabe908c2d4b4da7c to your computer and use it in GitHub Desktop.
Save tacigar/df02710d5ba166caabe908c2d4b4da7c to your computer and use it in GitHub Desktop.
クイックソートなり.
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