Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sort(some_array) # This "wraps" recursive_sort
- recursive_sort(some_array,[])
- end
- def recursive_sort(unsorted_array, sorted_array)
- ## the setup to compare two elements.
- sorted_array.push(unsorted_array[-1]) ## The size will get smaller
- unsorted_array.pop ## the more sorted it is
- x = (unsorted_array.length - 1)
- while x != -1
- if unsorted_array.empty? ## When we are done, this should be empty
- return sorted_array
- elsif unsorted_array[x].downcase < sorted_array[-1].downcase
- sorted_array.push(unsorted_array[x])
- unsorted_array.pop
- x = x - 1
- else
- x = x - 1
- end
- end
- return recursive_sort(unsorted_array,sorted_array)
- end
- z = ['g','A', 'h', 'J', 'a']
- puts sort(z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement