Skip to content

Commit b5310df

Browse files
authored
Merge pull request #26 from anuragmuxui/anuragmuxui-shell-sort
shell sort
2 parents cd3d548 + 439e7c5 commit b5310df

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Python/sorting/shell_sort.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from collections import Counter
2+
3+
def shell_sort(arr, freq):
4+
n=len(arr)
5+
gap=n//2
6+
while gap>0:
7+
for i in range(gap,n):
8+
temp=arr[i]
9+
j=i
10+
while j>=gap and (freq[arr[j-gap]],-arr[j-gap])<(freq[temp],-temp):
11+
arr[j]=arr[j-gap]
12+
j-=gap
13+
arr[j]=temp
14+
gap//=2
15+
16+
if __name__=="__main__":
17+
arr=[4,6,2,4,3,2,2,6]
18+
freq=Counter(arr)
19+
shell_sort(arr,freq)
20+
print(arr)

0 commit comments

Comments
 (0)