Skip to content

Instantly share code, notes, and snippets.

@bryangarza
Last active November 11, 2015 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryangarza/cc3f247778a0e8eca1b3 to your computer and use it in GitHub Desktop.
Save bryangarza/cc3f247778a0e8eca1b3 to your computer and use it in GitHub Desktop.
open Printf
let fetch_ints (size : int) : int array =
Array.init size (fun x -> read_int())
let insertion_sort =
let size = read_int() in
let sizep = pred size
and arr = fetch_ints size in
let x = arr.(sizep) in
let rec i_s arr i =
let ip = i-1 in
if arr.(ip) > x then (
arr.(i) <- arr.(ip);
Array.iter (printf "%d ") arr;
Printf.printf "\n";
i_s arr ip
) else (
arr.(i) <- x;
Array.iter (printf "%d ") arr
);
in i_s arr sizep;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment