Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 229cdf8

Browse files
Three Hundred - Twenty-Three Commit: Implement bucketsort() function
1 parent a64e078 commit 229cdf8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Bucket Sort with Hashing Function
2+
# =================================
3+
def bucketsort(A):
4+
n = len(A)
5+
maxelement = max(A)
6+
l = []
7+
buckets = [l] * 10
8+
for i in range(n):
9+
j = int(n * A[i] / (maxelement + 1))
10+
if len(buckets[j]) == 0:
11+
buckets[j] = [A[i]]
12+
else:
13+
buckets[j].append(A[i])
14+
for i in range(10):
15+
insertionsort(buckets[i])
16+
k = 0
17+
for i in range(10):
18+
for j in range(len(buckets[i])):
19+
A[k] = buckets[i].pop(0)
20+
k = k + 1

‎Section_11(Hash-Table)/(3)_bucket-sort.py

Whitespace-only changes.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /