sort algorithm
作者:互联网
n^2 sort
class Solution: """ @param a: an integer array @return: nothing """ def sort_integers1(self, a): # selection sort n = len(a) for i in range(n-1): # 在每轮比较中,将i 与 j(i之后的所有数) 进行比较,保证i是[i...]中最小值 for j in range(i+1, n): if a[i] > a[j]: a[i], a[j] = a[j], a[i] def sort_integers(self, a): # bubble sort n = len(a) for i in range(n-1): # 在每轮比较中,保证j和相邻的j+1是升序的 for j in range(n-1): if a[j] > a[j+1]: a[j], a[j+1] = a[j+1], a[j]
标签:sort,每轮,algorithm,self,len,range,def 来源: https://www.cnblogs.com/zijidan/p/16264431.html