标签:代码 时间 cat htm 单选 复杂度 selection arch target
选择排序:
http://www.cnblogs.com/chineking/archive/2011/05/24/implement-sort-algorithm-with-python.html
选择排序,是对冒泡排序法的一种改进,它的时间复杂度为O(n2)。
1 def selection_sort(sort_list): 2 iter_len = len(sort_list) 3 if iter_len < 2: 4 return sort_list 5 6 for i in range(iter_len-1): # i is the index 7 smallest = sort_list[i] 8 location = i 9 10 for j in range(i, iter_len): # j >= i 11 if sort_list[j] < smallest: # the latter < the former 12 smallest = sort_list[j] 13 location = j 14 15 if i != location: 16 sort_list[i], sort_list[location] = sort_list[location], sort_list[i] 17 18 return sort_list
标签:代码 时间 cat htm 单选 复杂度 selection arch target
原文地址:http://www.cnblogs.com/Noooo/p/6238486.html