Skip to content

Instantly share code, notes, and snippets.

@imouaddine
Created November 19, 2014 14:10
Show Gist options
  • Save imouaddine/3402ca5f45bbce6844aa to your computer and use it in GitHub Desktop.
Save imouaddine/3402ca5f45bbce6844aa to your computer and use it in GitHub Desktop.
def insert(a, index, value)
i = index
while(index >= 0 && value < a[i])
a[i+1] = a[i]
i -= 1
end
a[i+1] = value
end
def selection_sort(a)
(1).upto(a.length-1) do |i|
insert(a, i-1, a[i])
end
a
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment