Created
October 16, 2016 12:28
-
-
Save mykhailokrainik/b8ac01606f13a7f0bb82088d494a7bde to your computer and use it in GitHub Desktop.
SELECT SORT ALGORITHM
This file contains hidden or 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
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