Skip to content

Instantly share code, notes, and snippets.

@Nirma
Last active Aug 29, 2015
Embed
What would you like to do?
Radix Sort in Ruby
def radix (a, base = 10)
m = a.max
exp = 1
loop do
bkt = Array.new(base){[]}
a.each{|elem|
pos = (elem / exp) % base
bkt[pos] << elem
}
a = bkt.flatten
exp *= base
break if exp > m
end
a
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment