.>>>>>>>>>>>Counting sort in ruby(PL)
#author "shivamzaz" @imsec
a=[1,1,3,2] #take any one arrray
d=a.max
c=Array.new((d+1)) { |i| i=0 }
for i in 0...a.length
c[a[i]]+=1
end
for i in 1...c.length
c[i]=c[i]+c[i-1]
end
b=Array.new(c.max) {|v| v=0}
for i in (a.length-1).downto(0)
b[c[a[i]]]=a[i]
c[a[i]]-=1
end
i=a.min
while(b[i]!=nil)
puts b[i]
i+=1
end
>>>>>>>>>>>>>>happy coding<<<<<<<<<<<<<<<<<<
#author "shivamzaz" @imsec
a=[1,1,3,2] #take any one arrray
d=a.max
c=Array.new((d+1)) { |i| i=0 }
for i in 0...a.length
c[a[i]]+=1
end
for i in 1...c.length
c[i]=c[i]+c[i-1]
end
b=Array.new(c.max) {|v| v=0}
for i in (a.length-1).downto(0)
b[c[a[i]]]=a[i]
c[a[i]]-=1
end
i=a.min
while(b[i]!=nil)
puts b[i]
i+=1
end
>>>>>>>>>>>>>>happy coding<<<<<<<<<<<<<<<<<<