Skip to content

Instantly share code, notes, and snippets.

@blackknight36
Last active February 27, 2017 17:24
Show Gist options
  • Save blackknight36/638f9bee9146ce65b20b97dc50330905 to your computer and use it in GitHub Desktop.
Save blackknight36/638f9bee9146ce65b20b97dc50330905 to your computer and use it in GitHub Desktop.
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