From 5c37b33ab3ef3ec22c8ce596fff9ec4a490a4fc2 Mon Sep 17 00:00:00 2001 From: NatanLucena <44265910+NatanLucena@users.noreply.github.com> Date: Tue, 22 Oct 2019 16:41:30 -0300 Subject: [PATCH] Create ShellSort.py --- allalgorithms/sorting/ShellSort.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 allalgorithms/sorting/ShellSort.py diff --git a/allalgorithms/sorting/ShellSort.py b/allalgorithms/sorting/ShellSort.py new file mode 100644 index 0000000..148a1f2 --- /dev/null +++ b/allalgorithms/sorting/ShellSort.py @@ -0,0 +1,26 @@ +# -*- coding: UTF-8 -*- +# +# ShellSort algorithm +# The All â–²lgorithms library for python +# +# Contributed by: Natan Lucena +# Github: @NatanLucena +# + +def shellSort(arr): + n = len(arr) + gap = n//2 + + while gap > 0: + + for i in range(gap,n): + + temp = arr[i] + + j = i + while j >= gap and arr[j-gap] >temp: + arr[j] = arr[j-gap] + j -= gap + + arr[j] = temp + gap //= 2