Last active
December 25, 2018 01:28
-
-
Save Et7f3/1859b7aebe20612f092423e939888bb1 to your computer and use it in GitHub Desktop.
print a liste sorted
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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