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 d8db2d4

Browse files
Three Hundred - Twenty-Four Commit: Implement insertionsort() function
1 parent 229cdf8 commit d8db2d4

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Bucket Sort with Hashing Function
22
# =================================
3+
def insertionsort(A):
4+
n = len(A)
5+
for i in range(1, n):
6+
cvalue = A[i]
7+
position = i
8+
while position > 0 and A[position - 1] > cvalue:
9+
A[position] = A[position - 1]
10+
position = position - 1
11+
A[position] = cvalue
12+
13+
314
def bucketsort(A):
415
n = len(A)
516
maxelement = max(A)
@@ -17,4 +28,9 @@ def bucketsort(A):
1728
for i in range(10):
1829
for j in range(len(buckets[i])):
1930
A[k] = buckets[i].pop(0)
20-
k = k + 1
31+
k = k + 1
32+
33+
A = [63, 250, 835, 947, 651, 28]
34+
print('Original Array: ', A)
35+
bucketsort(A)
36+
print('Sort Array: ', A)

0 commit comments

Comments
(0)

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