Created
August 15, 2012 19:48
-
-
Save solomon081/3363037 to your computer and use it in GitHub Desktop.
Insertion Sort F#
This file contains 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 insert (a: array<int>) i item = | |
let mutable i = i - 1 | |
while i >= 0 && item < a.[i] do | |
a.[i + 1] <- a.[i] | |
i <- i - 1 | |
a.[i + 1] <- item | |
let isort (a: array<int>) = | |
let a = Array.copy a | |
for i in 1 .. (a.Length - 1) do | |
insert a i a.[i] | |
a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment