update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
|
|
@ -1,10 +1,10 @@
|
|||
class Array
|
||||
def countingsort!
|
||||
do_countingsort!(min, max)
|
||||
def counting_sort
|
||||
dup.counting_sort!
|
||||
end
|
||||
|
||||
protected
|
||||
def do_countingsort!(min, max)
|
||||
def counting_sort!
|
||||
min, max = minmax
|
||||
count = Array.new(max - min + 1, 0)
|
||||
each {|number| count[number - min] += 1}
|
||||
z = 0
|
||||
|
|
@ -20,5 +20,6 @@ class Array
|
|||
end
|
||||
|
||||
ary = [9,7,10,2,9,7,4,3,10,2,7,10,2,1,3,8,7,3,9,5,8,5,1,6,3,7,5,4,6,9,9,6,6,10,2,4,5,2,8,2,2,5,2,9,3,3,5,7,8,4]
|
||||
ary.countingsort!.join(",")
|
||||
p ary.counting_sort.join(",")
|
||||
|
||||
# => "1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,5,5,5,5,6,6,6,6,7,7,7,7,7,7,8,8,8,8,9,9,9,9,9,9,10,10,10,10"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue