Another opportunity to show me how to remove explicit loops!
http://rosettacode.org/wiki/Radix_sort

NB. queue implementation of LSB radix sort.
radixSort =: 3 : 0  NB. base radixSort data
16 radixSort y
:
keys =. x #.^:_1 y NB. compute keys
length =. {:#{.keys
extra =. (x,-length) {. ,. buckets =. i.x
for_pass. 0{i.-length do.
  keys =. ,&:>/ (buckets,keys{~"1<pass) <@:}./.extra,keys
  extra =. 1 |. extra
end.
x#.keys NB. restore the data
)

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to