内排序之直接选择排序
直接选择排序的套路比较容易理解, 就是从待排的元素里,挑最小或最大的出来,放到前面,然后迭代指针往后移一位...
直接上代码:def select_sorting(ary): n = len(ary) for i in range(n): min_index = i for j in range(i + 1, n): if ary[j] < ary[min_index]: min_index = j ary[i], ary[min_index] = ary[min_index], ary[i] return aryif __name__ == "__main__": arr1 = [3, 1, 2, 0, 4, -2] print arr1 print(select_sorting(arr1))