Advertisement
Guest User

Untitled

a guest
Sep 27th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. def sort(some_array) # This "wraps" recursive_sort
  2. recursive_sort(some_array,[])
  3. end
  4.  
  5. def recursive_sort(unsorted_array, sorted_array)
  6. ## the setup to compare two elements.
  7. sorted_array.push(unsorted_array[-1]) ## The size will get smaller
  8. unsorted_array.pop ## the more sorted it is
  9. x = (unsorted_array.length - 1)
  10. while x != -1
  11. if unsorted_array.empty? ## When we are done, this should be empty
  12. return sorted_array
  13. elsif unsorted_array[x].downcase < sorted_array[-1].downcase
  14. sorted_array.push(unsorted_array[x])
  15. unsorted_array.pop
  16. x = x - 1
  17. else
  18. x = x - 1
  19. end
  20. end
  21. return recursive_sort(unsorted_array,sorted_array)
  22. end
  23. z = ['g','A', 'h', 'J', 'a']
  24. puts sort(z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement