8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 11264ee + faa7988 commit 514f801Copy full SHA for 514f801
sorting/bucket_sort.py
@@ -0,0 +1,27 @@
1
+#!/usr/bin/env python3
2
+
3
+__author__ = "Aditya Krishnakumar"
4
5
6
+def bucket_sort(A):
7
+ buckets = [[] for x in range(10)]
8
+ for i, x in enumerate(A):
9
+ buckets[int(x * len(buckets))].append(x)
10
+ out = []
11
+ for buck in buckets:
12
+ out += isort(buck)
13
+ return out
14
15
16
+def isort(A):
17
+ if len(A) <= 1: return A
18
+ i = 1
19
+ while i < len(A):
20
+ k = A[i]
21
+ j = i - 1
22
+ while j >= 0 and A[j] > k:
23
+ A[j + 1] = A[j]
24
+ A[j] = k
25
+ j -= 1
26
+ i += 1
27
+ return A
0 commit comments