From db995b87351a0399dbac32e44fefe392a17a48b6 Mon Sep 17 00:00:00 2001 From: Pratyush Mishra <36813309+Pratyush2703@users.noreply.github.com> Date: Tue, 2 Oct 2018 02:15:25 +0800 Subject: [PATCH] Create insertionsort.py --- sorting/insertionsort.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 sorting/insertionsort.py diff --git a/sorting/insertionsort.py b/sorting/insertionsort.py new file mode 100644 index 0000000..011ba3f --- /dev/null +++ b/sorting/insertionsort.py @@ -0,0 +1,13 @@ +def insertionSort(arr): + + + for i in range(1, len(arr)): + + key = arr[i] + + + j = i-1 + while j >=0 and key < arr[j] : + arr[j+1] = arr[j] + j -= 1 + arr[j+1] = key