Skip to content

Instantly share code, notes, and snippets.

@daqing
Created June 7, 2009 11:04
Show Gist options
  • Save daqing/125287 to your computer and use it in GitHub Desktop.
Save daqing/125287 to your computer and use it in GitHub Desktop.
def insertion_sort(seq)
(1..seq.size - 1).each do |i|
key = seq[i]
left = i - 1
while left >= 0 and seq[left] > key
seq[left + 1] = seq[left]
seq[left] = key
left -= 1
end
end
seq
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment