Created
September 14, 2013 15:09
-
-
Save jli-hashrocket/6562774 to your computer and use it in GitHub Desktop.
Sorting problem in Ch. 12 section Rite of Passage:Sorting
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
| def sort(mylist) | |
| recursive_sort(mylist,[]) | |
| end | |
| def recursive_sort(unsorted_array, sorted_array) | |
| if unsorted_array[1] == nil | |
| sorted_array.push unsorted_array[0] | |
| false | |
| elsif unsorted_array[0] == nil | |
| false | |
| elsif unsorted_array[0] < unsorted_array[1] | |
| sorted_array.shift unsorted_array[0] | |
| elsif unsorted_array[1] < unsorted_array[0] | |
| sorted_array.shift unsorted_array[1] | |
| else | |
| end | |
| recursive_sort(unsorted_array, sorted_array) | |
| return sorted_array | |
| end | |
| keeploop = true | |
| wordcollect = [] | |
| while keeploop == true | |
| puts "Type a word" | |
| word = gets.chomp | |
| wordcollect.push "#{word}" | |
| if word == '' | |
| wordcollect.pop | |
| sort(wordcollect) | |
| keeploop = false | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment