def sort(alist): for passnum in range(len(alist)-1,0,-1): for i in range(passnum): if alist[i]>alist[i+1]: alist[i],alist[i+1] = alist[i+1],alist[i]
B.
def sort(lst): n = len(lst) if n <= 1: return lst for i in range(0,n-1): minIndex=i for j in range(i+1,n): #比较一遍,记录索引不交换 if lst[j] minIndex=j if minIndex !=i: #按索引交换 (lst[minIndex],lst[i])=(lst[i],lst[minIndex]) return lst
C.
def sort(alist): for index in range(1,len(alist)): currentvalue = alist[index] position = index while position>0 and alist[position-1]>currentvalue: alist[position]=alist[position-1] position = position-1 alist[position]=currentvalue
D.
def sort(arr): if len(arr) <= 1: return arr pivot=arr[len(arr) // 2] left=[x for x in arr if x < pivot] middle=[x for x in arr if x==pivot] right=[x for x in arr if x> pivot] return quicksort(left) + middle + quicksort(right)