From b9ae94e8736e7c7c2a141cf4e22f939dea67e75f Mon Sep 17 00:00:00 2001 From: AtomSolutions Date: Tue, 29 Oct 2019 20:52:06 +0800 Subject: [PATCH] Created new file insertion sorting py --- Sorting Algorithms/Python/insertion_sorting.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Sorting Algorithms/Python/insertion_sorting.py diff --git a/Sorting Algorithms/Python/insertion_sorting.py b/Sorting Algorithms/Python/insertion_sorting.py new file mode 100644 index 0000000..4f79407 --- /dev/null +++ b/Sorting Algorithms/Python/insertion_sorting.py @@ -0,0 +1,18 @@ +# Insertion sorting Algorithm +# @python + +def insertion_sort(list_): + + for x in range(1, len(list_)): + cursor = list_[x] + pos = x + + while pos > 0 and list_[pos - 1] > cursor: + list_[pos] = list_[pos - 1] + pos = pos - 1 + list_[pos] = cursor + return list_ + +array = [15, 2, 4, 50, 30, 2, 0, 1, 4] +sorted = insertion_sort(array) +print(sorted)