Home > Article > Backend Development > Flow chart of Python code implementing bucket sorting algorithm
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.
4. Enter other numbers in the array and repeat step 3, as shown in the figure:
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))
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!