算法导论初学之插入排序
arr = [8,2,4,7,3,6] length = len(arr) for j in range(1,length): key = arr[j] i = j-1 while i>-1 and arr[i]>key: arr[i+1] = arr[i] i = i-1 arr[i+1] = key print(arr)
arr = [8,2,4,7,3,6] length = len(arr) for j in range(1,length): key = arr[j] i = j-1 while i>-1 and arr[i]>key: arr[i+1] = arr[i] i = i-1 arr[i+1] = key print(arr)