Skip to content

Instantly share code, notes, and snippets.

@dhiraka
Created December 1, 2014 07:22
Show Gist options
  • Save dhiraka/251c55ce45ffc8fac410 to your computer and use it in GitHub Desktop.
Save dhiraka/251c55ce45ffc8fac410 to your computer and use it in GitHub Desktop.
def insertionSort(array)
(1..array.length-1).each do |i|
temp=array[i]
j=i-1
while(j>=0 && array[j]>temp)
array[j+1]=array[j]
j -= 1
end
array[j+1]=temp
end
return array
end
x=[5,3,8,1,7,9]
puts insertionSort(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment