You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
box-o-sand/sorting.py

12 lines
247 B

13 years ago
# vim:fileencoding=utf-8
def insertion_sort(a):
13 years ago
""" Θ(n^2) """
for j in range(1, len(a)):
key = a[j]
i = j - 1
while i >= 0 and a[i] > key:
a[i + 1] = a[i]
i = i - 1
a[i + 1] = key