From d5e7f537e6a4dd45f1a44b7b91de50ed42a84d16 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Mon, 15 Aug 2011 06:35:27 -0400 Subject: [PATCH] working through mit intro to algorithms, first with insertion sort --- insertion_sort01.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 insertion_sort01.py 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