forked from piyush-kash/Hacktober2021-cpp-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbin_sort.py
More file actions
35 lines (27 loc) · 650 Bytes
/
Copy pathbin_sort.py
File metadata and controls
35 lines (27 loc) · 650 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# This is bin sor algorithm
MIN_BUCKET = 0
MAX_BUCKET = 15
def bucket_sort(aList):
buckets = list()
for i in range(MIN_BUCKET, MAX_BUCKET + 1):
buckets.append(None)
for i in aList:
buckets[aList[i]] = aList[i]
x = 0
for i in range(MIN_BUCKET, MAX_BUCKET + 1):
if buckets[i] is not None:
aList[x] = buckets[i]
x += 1
return aList
if __name__ == '__main__':
from random import shuffle
l = range(15)
lcopy = l[:]
shuffle(l)
print('Unsorted')
print l
assert l != lcopy
print('Sorted')
l = bucket_sort(l)
print l
assert l == lcopy