选择排序

2019-03-07  本文已影响0人  开始懂了90
#encoding:utf-8
def smallNum(arr):  
    small_index = 0
    small = arr[0]
    for i in range(1, len(arr)):              
        if arr[i] < small:
            small = arr[i]
            small_index = i
   # return small
    return small_index

def choseSort(arr):
    new = []

    for i in range(len(arr)):
        sn = smallNum(arr)
   #     new.append(sn)
   #     arr.remove(sn)
        new.append(arr.pop(sn))
    return new

print choseSort([3,4,51,34,0])
上一篇 下一篇

猜你喜欢

热点阅读