Skip to content

Instantly share code, notes, and snippets.

@gofer
Last active December 30, 2015 14:19
Show Gist options
  • Save gofer/7841581 to your computer and use it in GitHub Desktop.
Save gofer/7841581 to your computer and use it in GitHub Desktop.
Insert Sort
(* insert sort *)
fun insert_sort nil = nil
| insert_sort (y::ys) = let
fun insert n nil = [n]
| insert n (x::xs) = if x < n then (x::(insert n xs)) else (n::(x::xs));
in
insert y (insert_sort ys)
end;
insert_sort [5, 1, 2, 4, 1, 3];
(* val it = [1,1,2,3,4,5] : int list *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment