fundalmentals of algorithm

tech2023-05-17  111

# insert_sort a = [1,5,3,8,10,2,6,3] for i in range(1,len(a)): key = a[i] j = i - 1 while j >= 0 and a[j] > key: a[j+1] = a[j] j = j - 1 a[j+1] = key print(a) # insert_sort decrease b = [8,3,5,7,2,9,1] for i in range(1,len(b)): key = b[i] j = i - 1 while j >= 0 and b[j] < key: b[j+1] = b[j] j = j - 1 b[j+1] = key print(b)
最新回复(0)