We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents cd3d548 + 439e7c5 commit b5310dfCopy full SHA for b5310df
1 file changed
Python/sorting/shell_sort.py
@@ -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