import sys
sys.path.append("..")
from algo_utils.test_utils import TestUtils as tu


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:
        '''how handle 0.xx number'''
        # index_b = int(10 * j)
        # bucket[index_b].append(j)
        bucket[int(j)].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


# # sample = tu.gen_unique_int(10)
# sample = tu.gen_random(1, 10, 10)
# # print(sample)
# # sample = [.42, .32, .33, .52, .37, .47, .51]
# print(bucketSort(sample))
import sys
sys.path.append("..")
from algo_utils.test_utils import TestUtils as tu


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:
        '''how handle 0.xx number'''
        # index_b = int(10 * j)
        # bucket[index_b].append(j)
        bucket[int(j)].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


# # sample = tu.gen_unique_int(10)
# sample = tu.gen_random(1, 10, 10)
# # print(sample)
# # sample = [.42, .32, .33, .52, .37, .47, .51]
# print(bucketSort(sample))
# Create empty buckets # Insert elements into their respective buckets how handle 0.xx number # index_b = int(10 * j) # bucket[index_b].append(j) # Sort the elements of each bucket # Get the sorted elements # # sample = tu.gen_unique_int(10) # sample = tu.gen_random(1, 10, 10) # # print(sample) # # sample = [.42, .32, .33, .52, .37, .47, .51] # print(bucketSort(sample))