Selection sort in Python

Selection sort

def selection_sort(list_02):
    for j in range(len(list_02) - 1):
        min_index = j
        for i in range(j + 1, len(list_02)):
            if list_02[min_index] > list_02[i]:
                min_index = i
        list_02[j], list_02[min_index] = list_02[min_index], list_02[j]

def main():
    list_01 = [2, 4, 55, 1, 6, 28, 54, 55, 19, 95, 48, 65]
    selection_sort(list_01)
    print(list_01)

if __name__ == '__main__':
    main()

---------------results of enforcement----------
[1, 2, 4, 6, 19, 28, 48, 54, 55, 55, 65, 95]

-----------------------------------------------

猜你喜欢

转载自blog.csdn.net/Xcq007/article/details/82050998