Skip to content

the file "https://github.com/TheAlgorithms/Python/blob/master/sorts/bucket_sort.py" i think it can be come true by the method of bubble sort,like this: #622

@chianoceanwhale

Description

@chianoceanwhale
def bubbleSort(src_list, flag_value):
    '''
    the bisection is helpful to come ture which is sort
    :param src_list:
    :param flag_value: “dataup” is sort by ascending; "datadown" is sort by descending
    :return:
    '''
    src_len = len(src_list)
    if ("dataup" == flag_value):
        for i in range(src_len):
            for j in range(src_len):
                if src_list[i] < src_list[j]:
                    mid_size = src_list[i]
                    src_list[i] = src_list[j]
                    src_list[j] = mid_size
    elif ("datadown" == flag_value):
        for i in range(src_len):
            for j in range(src_len):
                if src_list[i] > src_list[j]:
                    mid_size = src_list[i]
                    src_list[i] = src_list[j]
                    src_list[j] = mid_size
    else:
        print("error")
    return src_list
if __name__ == '__main__':
    ret = bubbleSort([12, 23, 4, 5, 3, 2, 12, 81, 56, 95],"dataup")
    print(ret)
    ret1 = bubbleSort([-2, -5, -45],"dataup")
    print(ret1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions