Python 简单选择排序算法代码实现

# -*- coding:utf8 -*-
def select_sort(origin_items, comp=lambda x, y: x < y ):
    '''简单选择排序'''
    items = origin_items[:]
    for i in range(len(items) -1):
        min_index = i
        for j in range(i + 1, len(items)):
            if comp(items[j], items[min_index]):
                min_index = j
        items[i], items[min_index] = items[min_index], items[i]
    return items

print(select_sort([9,3,5,2,1,10,24,30]))

你可能感兴趣的:(数据结构,排序算法,python,算法)