Skip to content

Instantly share code, notes, and snippets.

@miry
Last active August 30, 2018 19:16
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 miry/5041869 to your computer and use it in GitHub Desktop.
Save miry/5041869 to your computer and use it in GitHub Desktop.
def insertionSort(ar)
j = 1
while j < ar.size
i = j - 1
key = ar[j]
while i >= 0 && key < ar[i]
ar[i+1]=ar[i]
puts ar.join(" ")
i -= 1
end
if ar[j] != key
ar[ i + 1 ] = key
puts ar.join(" ")
end
j += 1
end
end
# Tail starts here
_ar_cnt = gets.to_i
_ar = gets.split(" ")[0.._ar_cnt].map!(&:to_i)
insertionSort(_ar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment