Last active
August 8, 2018 14:51
-
-
Save Bablzz/49f98163b31e74f6b0dc3429feadf854 to your computer and use it in GitHub Desktop.
selection sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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