#!/usr/bin/python#coding: utf-8def select_sort ( li , num ):"选择法排序"for i in range ( num - 1 ): # 对位置进行遍历min = i # 把i位置记做最小值for j in range ( i + 1 , num ): # 查找i之后的所有位置的最小值if li [ i ] > li [ j ]: # 如果找到了则把最小值赋值给jmin = j# 如果说min不是i,则证明后面有更小的,进行交换if min != i :li [ i ], li [ min ] = li [ min ], li [ i ]if __name__ == "__main__" :li = [ 95 , 45 , 15 , 78 , 84 , 51 , 24 , 12 ]select_sort ( li , len ( li ))print li