let rec quickSort (data:int list) =
match data with
| [] -> []
| [a] -> [a]
| head::tail ->
let l0 =
tail
| > List.filter ((<=) head)
let l1 =
tail
| > List.filter ((>) head)
quickSort(l0) @ [head] @ quickSort(l1)
quickSort [-2; -3; 4; -1; 0; 1; 5; 7; -2]
match data with
| [] -> []
| [a] -> [a]
| head::tail ->
let l0 =
tail
| > List.filter ((<=) head)
let l1 =
tail
| > List.filter ((>) head)
quickSort(l0) @ [head] @ quickSort(l1)
quickSort [-2; -3; 4; -1; 0; 1; 5; 7; -2]
1 comment:
Using List.partition even more concise :)
let rec quickSort (l : _ list) =
match l with
| hd :: tl ->
let lt, gtq = tl |> List.partition ((>) hd)
quickSort lt @ hd :: quickSort gtq
| _ -> []
Post a Comment