Re: Problem !!!
- Posted by Robert Craig <robert_craig at COMPUSERVE.COM> Feb 21, 1997
- 911 views
Jacques Deschenes writes: > What a suprise to read that. A sort with *zero* comparisons! > By nature sorting means comparing. I would certainly be happy to see > that miraculous sort. -- bucket sort ------------------------------------------------------ function bucket_sort(sequence s, integer min_value, integer max_value) -- Sort s into ascending order. No elements are compared. -- The values of s must be integers from min_value to max_value sequence count, sorted integer value count = repeat(0, max_value-min_value+1) s = s - (min_value - 1) for i = 1 to length(s) do value = s[i] count[value] = count[value]+1 end for sorted = {} for i = 1 to length(count) do sorted = sorted & repeat(i, count[i]) end for return sorted + (min_value - 1) end function ? bucket_sort({25,7,2,5,200,14,7,10}, 1, 256) ------------------------------------------------- Regards, Rob Craig Rapid Deployment Software