Python 버킷정렬 구현

1 개요[ | ]

Python 버킷정렬 구현
파이썬 버킷정렬 구현
Python
Copy
def bucket_sort(a):
    size = len(a)
    buckets = [[] for _ in range(size)]
    for x in a: buckets[int(x*size)].append(x)
    for b in buckets: b.sort()
    pos = 0
    for b in buckets:
        bsize = len(b)
        a[pos:pos+bsize] = b
        pos += bsize
arr = [0.44, 0.1, 0.99, 0.9, 0.0, 0.1, 0.43]
bucket_sort( arr )
print( arr )
# [0.0, 0.1, 0.1, 0.43, 0.44, 0.9, 0.99]

2 같이 보기[ | ]