Counting sort

func counting_sort(a, min, max) {
    var cnt = ([0] * (max - min + 1))
    a.each {|i| cnt[i-min]++ }
    cnt.map {|i| [min++] * i }.flat
}
 
var a = 100.of { 100.irand }
say counting_sort(a, 0, 100)

Last updated