Home > Backend Development > Python Tutorial > Flow chart of Python code implementing bucket sorting algorithm

Flow chart of Python code implementing bucket sorting algorithm

WBOY
Release: 2024-01-24 20:27:06
forward
1084 people have browsed it

The simple understanding of the bucket sorting algorithm is to disperse the data into buckets, then sort the data in each bucket, and finally arrange the data in order.

桶排序算法流程图 Python代码实现桶排序

4. Enter other numbers in the array and repeat step 3, as shown in the figure:

桶排序算法流程图 Python代码实现桶排序

Python code to implement bucket sorting

def bucketSort(array):
    bucket = []

    for i in range(len(array)):
        bucket.append([])

    for j in array:
        index_b = int(10 * j)
        bucket[index_b].append(j)

    for i in range(len(array)):
        bucket[i] = sorted(bucket[i])

    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))
Copy after login

The above is the detailed content of Flow chart of Python code implementing bucket sorting algorithm. For more information, please follow other related articles on the PHP Chinese website!

source:163.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template