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