From c762fb447c8fe3d690e2daffc7eb703a09353aa4 Mon Sep 17 00:00:00 2001 From: Akash Srivastava <43779954+Dev-Akash@users.noreply.github.com> Date: Tue, 8 Oct 2019 07:30:29 +0530 Subject: [PATCH] Create Insertion_sort.py Added a basic sorting algo. --- python basics/Insertion_sort.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 python basics/Insertion_sort.py diff --git a/python basics/Insertion_sort.py b/python basics/Insertion_sort.py new file mode 100644 index 0000000..4d755bf --- /dev/null +++ b/python basics/Insertion_sort.py @@ -0,0 +1,14 @@ +# This program will demonstrate the +# Insertion sorting. + +a = [54, 32, 32, 5, 82, 34, 5, 9] + +for i in range(1, len(a), 1): + key = a[i] + j = i-1 + while(j>-1 and a[j]>key): + a[j+1] = a[j] + j = j-1 + a[j+1] = key + +print(a) \ No newline at end of file