commit d5e7f537e6a4dd45f1a44b7b91de50ed42a84d16 Author: Dan Buch Date: Mon Aug 15 06:35:27 2011 -0400 working through mit intro to algorithms, first with insertion sort diff --git a/insertion_sort01.py b/insertion_sort01.py new file mode 100644 index 0000000..29ab2f1 --- /dev/null +++ b/insertion_sort01.py @@ -0,0 +1,8 @@ +def insertion_sort(A): + 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