Last active
February 27, 2017 17:24
-
-
Save blackknight36/638f9bee9146ce65b20b97dc50330905 to your computer and use it in GitHub Desktop.
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
def print_arr(ar) | |
ar.each do |i| | |
printf("%d ", i) | |
end | |
puts | |
end | |
def insertionSort(a) | |
n = a.length - 1 | |
for i in (1..n) do | |
value = a[i] | |
h = i | |
while h > 0 and a[h-1] > value do | |
a[h] = a[h-1] | |
h -= 1 | |
end | |
a[h] = value | |
end | |
return a | |
end | |
ar = gets.strip.split.map {|i| i.to_i} | |
ar = insertionSort(ar, ar.length) | |
print_arr(ar) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment