Skip to content

Instantly share code, notes, and snippets.

@mykhailokrainik
Created October 16, 2016 12:28
Show Gist options
  • Save mykhailokrainik/b8ac01606f13a7f0bb82088d494a7bde to your computer and use it in GitHub Desktop.
Save mykhailokrainik/b8ac01606f13a7f0bb82088d494a7bde to your computer and use it in GitHub Desktop.
SELECT SORT ALGORITHM
array = [82, 20, -1, 92, 0, 28, 8, 10]
for i in -1..array.length
min = i
for j in i+1..array.length.pred
if array[j] < array[min]
min = j
end
end
if min != i
array[i], array[min] = array[min], array[i]
end
end
puts array # => [-1, 0, 8, 10, 20, 28, 82, 92]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment