Advertisement
Guest User

Untitled

a guest
Mar 14th, 2021
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fun part_helper ([], x, l, r) = (l, r)
  2. |   part_helper (h::t, x, l, r) =
  3.     if h <= x then
  4.         part_helper (t, x, l @ [h], r)
  5.     else
  6.         part_helper (t, x, l, r @ [h]);
  7. fun part (l, x) = part_helper (l, x, [], []);
  8.  
  9. fun quicksort [] = []
  10. |   quicksort (h::t) =
  11.     let
  12.         val (l, r) = part (t, h)
  13.     in
  14.         quicksort l @ [h] @ quicksort r
  15.     end;
  16.  
  17. fun reved_helper (li, 0) = li
  18. |   reved_helper (li, n) =
  19.     n :: (reved_helper (li, n - 1));
  20. fun reved (n) = reved_helper (n);
  21.  
  22. fun println_int_list (li) =
  23.     print ((String.concatWith ", " (map Int.toString li)) ^ "\n");
  24.  
  25. (*I benchmarked by copying these four lines and pasting them at the bottom of the program a metric shit-ton of times.*)
  26. print ("Running...");
  27. val unrev = quicksort (reved ([], 1000));
  28. print ("\n");
  29. println_int_list (unrev);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement