python 代码实现选择排序

def select_sort(new_list):
    '''选择排序'''
    n = len(new_list)
    for j in range(n-1):
        min = j
        for i in range(j+1, n):
            if new_list[min] > new_list[i]:
                min = i
        new_list[j],new_list[min] = new_list[min], new_list[j]

if __name__ == '__main__':
    new_list = [9, 5, 99, -8, 32, 700, -4]
    print(new_list)
    select_sort(new_list)
    print(new_list)

C:\Users\user\AppData\Local\Programs\Python\Python36\python.exe “C:/Users/user/PycharmProjects/hellow python/test.py”
[9, 5, 99, -8, 32, 700, -4]
[-8, -4, 5, 9, 32, 99, 700]

Process finished with exit code 0

上一篇:For noip2019 初赛(csp)


下一篇:1