Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions allalgorithms/sorting/ShellSort.py
Original file line number Diff line number Diff line change
@@ -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