1 개요[ | ]
- Ruby 버킷정렬 구현
- 루비 버킷정렬 구현
Ruby
Copy
def bucket_sort(a)
size=a.size
buckets=[]
size.times{ buckets.push([]) }
for x in a; buckets[(x*size).floor].push(x); end
for b in buckets; b.sort!; end
pos=0
for b in buckets
a[pos,b.size] = b
pos += b.size
end
end
arr = [0.0, 0.1, 0.1, 0.43, 0.44, 0.9, 0.99]
bucket_sort( arr )
print( arr )
# [0.0, 0.1, 0.1, 0.43, 0.44, 0.9, 0.99]
2 같이 보기[ | ]
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.