-
-
Save anonymous/ab8ec3dfa8820a804323 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
puts "Please enter your words - one per line. To exit press enter on a empty line" | |
words_array = [] | |
words_array.push gets.chomp while words_array.last != '' | |
words_array.pop | |
array_size = words_array.length | |
sorted_array = Array.new(array_size) | |
words_array.each do |word| | |
count = 1 | |
array_order = 0 | |
while count <= array_size | |
if word > words_array[count-1] | |
array_order += 1 | |
end | |
count += 1 | |
end | |
sorted_array[array_order] = word | |
end | |
puts | |
puts sorted_array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment