python排序算法实现(冒泡.选择.插入) python 从小到大排序 1.冒泡排序: O(n2) s=[3,4,2,5,1,9] #count = 0 for i in range(len(s)): for j in range((i+1),len(s)): s[i],s[j]=min(s[i],s[j]),max(s[i],s[j]) #print count print s 2.选择排序: O(n2) s=[3,4,2,5,1,9] #count = 0 for i in range(l
先学习之前未完成的冒泡算法 li = [13,22,6,99,11] 从小到大 从第一个数字比较把大的往后移位 for m in range(4): num1 = li[m] num2 = li[m+1] if num1 > num2: temp = li[m] li[m] = num2 li[m+1] = temp print li 循环四次就把最大数放到列表的最后 for m in range(3): num1 = li[m] num2 = li[m+1] if num1 > num2: