box-o-sand/insertion_sort01.py

9 lines
201 B
Python
Raw Normal View History

2011-08-15 10:47:22 +00:00
def insertion_sort(a):
for j in range(1, len(a)):
key = a[j]
i = j - 1
2011-08-15 10:47:22 +00:00
while i >= 0 and a[i] > key:
a[i + 1] = a[i]
i = i - 1
2011-08-15 10:47:22 +00:00
a[i + 1] = key