From 52864bacb9ac60d3e04efce4493677a9cbe7e838 Mon Sep 17 00:00:00 2001 From: Kenneth Nero Date: Fri, 26 Oct 2018 10:25:43 -0400 Subject: [PATCH] Updated sorting folder with shell.py Implemented a shell sort program in python. --- sorting/shell.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 sorting/shell.py diff --git a/sorting/shell.py b/sorting/shell.py new file mode 100644 index 0000000..1e7c799 --- /dev/null +++ b/sorting/shell.py @@ -0,0 +1,19 @@ +def shell(inp): + gap = int(len(inp) / 2) +# Primary gap loop, run until its sorted. + while gap > 0: + for i in range(gap, len(inp)): + temp = inp[i] + j = i +# Sort for a given 'gap' + while j >= gap and inp[j - gap] > temp: + inp[j] = inp[j - gap] + j = j-gap + inp[j] = temp +# Shrink gap for the next section + gap = int(gap/2) + +list = [239, 152, 110, 223, 96, 203, 179, 23, 213, 280] + +shell(list) +print(list)