选择排序(LOW)

博客地址:https://www.cnblogs.com/zylyehuo/

# _*_coding:utf-8_*_

def select_sort(li):
    for i in range(len(li)-1): # i是第几趟
        min_loc = i
        for j in range(i+1, len(li)):
            if li[j] < li[min_loc]:
                min_loc = j
        li[i], li[min_loc] = li[min_loc], li[i]
        print(li)

li = [3,4,2,1,5,6,8,7,9]
print(li)
select_sort(li)

posted @ 2023-08-12 17:05  zylyehuo  阅读(5)  评论(0编辑  收藏  举报