From 6fc8e21851fb9df4fcb04351e2f2887debfe7ebe Mon Sep 17 00:00:00 2001 From: chmod777 Date: Wed, 4 Jul 2018 20:43:12 +0100 Subject: [PATCH 1/3] added insertion sort python algorithme --- .../insertion/code/python/insertion.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 chapters/sorting_searching/insertion/code/python/insertion.py diff --git a/chapters/sorting_searching/insertion/code/python/insertion.py b/chapters/sorting_searching/insertion/code/python/insertion.py new file mode 100644 index 000000000..13f8ca2ad --- /dev/null +++ b/chapters/sorting_searching/insertion/code/python/insertion.py @@ -0,0 +1,10 @@ +def insertion_sort(A): + for i in range(1, len(A)): + j = i-1 + while A[j] > A[j+1] and j >= 0: + A[j], A[j+1] = A[j+1], A[j] + j -= 1 + + +A = [5,9,1,2,4,8,6,3,7] +print(insertion_sort(A)) From 016325315545d61a140da1712069d728fac79f4d Mon Sep 17 00:00:00 2001 From: chmod777 Date: Wed, 4 Jul 2018 20:48:44 +0100 Subject: [PATCH 2/3] corrected wrong naming --- .../python/insertion.py => selection/code/python/selection.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename chapters/sorting_searching/{insertion/code/python/insertion.py => selection/code/python/selection.py} (100%) diff --git a/chapters/sorting_searching/insertion/code/python/insertion.py b/chapters/sorting_searching/selection/code/python/selection.py similarity index 100% rename from chapters/sorting_searching/insertion/code/python/insertion.py rename to chapters/sorting_searching/selection/code/python/selection.py From ed1e252bb59f159eb278ce105a139431ed072fdc Mon Sep 17 00:00:00 2001 From: chmod777 Date: Wed, 4 Jul 2018 20:58:13 +0100 Subject: [PATCH 3/3] corrected wrong script --- .../selection/code/python/selection.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/chapters/sorting_searching/selection/code/python/selection.py b/chapters/sorting_searching/selection/code/python/selection.py index 13f8ca2ad..dd99f00a4 100644 --- a/chapters/sorting_searching/selection/code/python/selection.py +++ b/chapters/sorting_searching/selection/code/python/selection.py @@ -1,10 +1,7 @@ -def insertion_sort(A): - for i in range(1, len(A)): - j = i-1 - while A[j] > A[j+1] and j >= 0: - A[j], A[j+1] = A[j+1], A[j] - j -= 1 - - -A = [5,9,1,2,4,8,6,3,7] -print(insertion_sort(A)) +def selectionList(lst): + for i in range(0, len(lst)): + if i < len(lst): + lst[i] = i + return lst +t = [1,0,3,2,6,4,5,9,7,8] +print(selectionList(t))