- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellsort.py
More file actions
Latest commit
32 lines (23 loc) · 725 Bytes
/
Copy pathshellsort.py
File metadata and controls
32 lines (23 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
fromgeneratorimportGenerator
defShellSort(arr: list) ->list:
n=len(arr)
gap=n//2
whilegap>0:
j=gap
# Check from left to right
whilej<n:
i=j-gap# Maintain gap value
whilei>0:
# If value on right side is greater than left don't swap
ifarr[i+gap] >arr[i]:
break
else:
arr[i+gap], arr[i] =arr[i], arr[i+gap]
i=i-gap# Check left side
j+=1
gap=gap//2
returnarr
if__name__=='__main__':
arr=Generator(1000)
sorted_list=ShellSort(arr)
print(sorted_list)