Skip to content

Instantly share code, notes, and snippets.

@Ollie-Boyd
Last active April 29, 2020 12:17
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 Ollie-Boyd/023b86c3461436f1418aa24ba4ba55a3 to your computer and use it in GitHub Desktop.
Save Ollie-Boyd/023b86c3461436f1418aa24ba4ba55a3 to your computer and use it in GitHub Desktop.
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