Skip to content

Instantly share code, notes, and snippets.

@Bablzz
Last active August 8, 2018 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bablzz/49f98163b31e74f6b0dc3429feadf854 to your computer and use it in GitHub Desktop.
Save Bablzz/49f98163b31e74f6b0dc3429feadf854 to your computer and use it in GitHub Desktop.
selection sort
arr = [9,81,-9,3,0,12,-10]
def find_min(list)
min = list[0]
index = 0
list.each_with_index do |val, i|
if val < min
min = val
index = i
end
end
list.delete_at(index)
end
def selection_sort(list)
newArr = []
while list.length != 0
newArr.push(find_min(list))
end
puts newArr
end
selection_sort(arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment