Skip to content

Instantly share code, notes, and snippets.

@danmelnick
Created August 30, 2010 00:15
Show Gist options
  • Save danmelnick/556845 to your computer and use it in GitHub Desktop.
Save danmelnick/556845 to your computer and use it in GitHub Desktop.
def insertion_sort(array)
n = 1
while n < array.length
key = array[n]
i = n - 1
while i >= 0 and array[i] > key
array[i + 1] = array[i]
i = i - 1
end
array[i + 1] = key
n = n + 1
end
return array
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment