Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/sort.rb
Instance Method Summary collapse
Instance Method Details
#radix_sort ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/sort.rb', line 6 def radix_sort input_array = dup (Math.log10(input_array.max.abs).floor + 1).times { |index| buckets = Array.new(10) { Array.new } input_array.each { |val| buckets[val % (10 ** (index + 1)) / (10 ** (index))] << val } input_array = buckets.flatten } input_array end |
#radix_sort! ⇒ Object
2 3 4 |
# File 'lib/sort.rb', line 2 def radix_sort! replace radix_sort end |