Last active
August 30, 2018 19:16
-
-
Save miry/5041869 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
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