Last active
April 29, 2020 12:17
-
-
Save Ollie-Boyd/023b86c3461436f1418aa24ba4ba55a3 to your computer and use it in GitHub Desktop.
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
def sorter wordlist, sorted_array=[], index=0 | |
if index==wordlist.length() | |
return sorted_array | |
end | |
sorted_array.push(wordlist[index]) | |
def check_and_swap sorted_array, index | |
if index != 0 | |
if sorted_array[index]<sorted_array[index-1] | |
sorted_array[index], sorted_array[index-1] = sorted_array[index-1], sorted_array[index] | |
check_and_swap(sorted_array, index-1) | |
end | |
end | |
end | |
check_and_swap(sorted_array, index) | |
sorter(wordlist, sorted_array, index+1) | |
end | |
start = Time.now | |
puts sorter wordlist | |
finish = Time.now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment