Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun part_helper ([], x, l, r) = (l, r)
- | part_helper (h::t, x, l, r) =
- if h <= x then
- part_helper (t, x, l @ [h], r)
- else
- part_helper (t, x, l, r @ [h]);
- fun part (l, x) = part_helper (l, x, [], []);
- fun quicksort [] = []
- | quicksort (h::t) =
- let
- val (l, r) = part (t, h)
- in
- quicksort l @ [h] @ quicksort r
- end;
- fun reved_helper (li, 0) = li
- | reved_helper (li, n) =
- n :: (reved_helper (li, n - 1));
- fun reved (n) = reved_helper (n);
- fun println_int_list (li) =
- print ((String.concatWith ", " (map Int.toString li)) ^ "\n");
- (*I benchmarked by copying these four lines and pasting them at the bottom of the program a metric shit-ton of times.*)
- print ("Running...");
- val unrev = quicksort (reved ([], 1000));
- print ("\n");
- println_int_list (unrev);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement