Insertion sort

python实现:

def insert_sort(A):
for i in range(1, len(A)):
key = A[j]
i = j - 1
while i >= 0 and A[i] > key:
A[i + 1] = A[i]
i -= 1
A[i + 1] = key

插入算法工作方式举例说明source:wikipedea
里面有很是详尽。如果再来叙述,有点画蛇添足的嫌疑了。。。

你可能感兴趣的:(Insertion sort)