Skip to content

Instantly share code, notes, and snippets.

@Et7f3
Last active December 25, 2018 01:28
Show Gist options
  • Save Et7f3/1859b7aebe20612f092423e939888bb1 to your computer and use it in GitHub Desktop.
Save Et7f3/1859b7aebe20612f092423e939888bb1 to your computer and use it in GitHub Desktop.
print a liste sorted
let print_sorted =
let rec filter acc f = function
[] -> []
| e :: l when e = f -> List.rev acc @ l
| e :: l -> filter (e :: acc) f l
in let rec minimum m = function
[] -> m
| e :: l -> minimum (min e m) l
in let rec p = function
[] -> ()
| m :: [] -> print_string (string_of_int m)
| e :: l -> let m = minimum e l in
print_string (string_of_int m ^ " ");
p (filter [] m (e :: l))
in p
let () = print_sorted [-2; 4; 8; 3; -7; 4]
let print_sorted = function
[] -> ()
| c :: d -> let rec sort min = function
[], [] -> print_int min
| [], a :: b -> print_int min;
print_string " ";
sort a (b, [])
| a :: b, list2 -> if a < min then
sort a (b, min :: list2)
else
sort min (b, a :: list2)
in sort c (d, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment