Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Bucket_sort.Py #142

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Others/Bucket_sort.Py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Bucket Sort in Python


def bucketSort(array):
bucket = []

# Create empty buckets
for i in range(len(array)):
bucket.append([])

# Insert elements into their respective buckets
for j in array:
index_b = int(10 * j)
bucket[index_b].append(j)

# Sort the elements of each bucket
for i in range(len(array)):
bucket[i] = sorted(bucket[i])

# Get the sorted elements
k = 0
for i in range(len(array)):
for j in range(len(bucket[i])):
array[k] = bucket[i][j]
k += 1
return array


array = [.42, .32, .33, .52, .37, .47, .51]
print("Sorted Array in descending order is")
print(bucketSort(array))