python实现插入排序与选择排序
#!/usr/bin/env python # -*- coding: utf-8 -*- def insert_sort(arr): l = len(arr) - 1 for i in xrange(1, l): for j in xrange(i, 0, -1): if arr[j] < arr[j-1]: arr[j], arr[j-1] = arr[j-1], arr[j] #print range(5, 0, -1) def choose_sort(arr): l = len(arr) - 1 for i in xrange(0, l - 1): for j in xrange(i + 1, l): if arr[j] < arr[i]: arr[j], arr[i] = arr[i], arr[j]