Created
July 5, 2018 12:39
-
-
Save dmitryshelomanov/af151aec98a805231ca088976a754335 to your computer and use it in GitHub Desktop.
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
module BubleSort = { | |
let make = () => { | |
let data = [|4, 3, 5, 0, 1, 10, 8, 2, 9|]; | |
for (i in Array.length(data) - 1 downto 0) { | |
for (j in 0 to i - 1) { | |
if (data[j] > data[j + 1]) { | |
let tmp = data[j]; | |
data[j] = data[j + 1]; | |
data[j + 1] = tmp; | |
}; | |
}; | |
}; | |
Js.log(data); | |
}; | |
}; | |
module InsertedSort = { | |
let make = () => { | |
let data = [|4, 3, 5, 0, 1, 10, 8, 2, 9|]; | |
for (i in 0 to Array.length(data) - 1) { | |
for (j in i downto 0) { | |
if (j > 0 && data[j] < data[j - 1]) { | |
let tmp = data[j]; | |
data[j] = data[j - 1]; | |
data[j - 1] = tmp; | |
}; | |
}; | |
}; | |
Js.log(data); | |
}; | |
}; | |
InsertedSort.make(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment