From c0b2414bcd11784fe9d2f8784e1afeed9a44e6fc Mon Sep 17 00:00:00 2001 From: Robin Rognerud Date: Thu, 31 Oct 2019 15:57:09 +0100 Subject: [PATCH] added insertion sort --- python/insertion_sort.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 python/insertion_sort.py diff --git a/python/insertion_sort.py b/python/insertion_sort.py new file mode 100644 index 0000000..483ed88 --- /dev/null +++ b/python/insertion_sort.py @@ -0,0 +1,8 @@ +def insertionsort(liste): + for j in range(1,len(liste)): + key = liste[j] + i = j - 1 + while i >= 0 and key < liste[i]: + liste[i+1] = liste[i] + i -= 1 + liste[i+1] = key