-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellSort.py
More file actions
33 lines (20 loc) · 707 Bytes
/
Copy pathShellSort.py
File metadata and controls
33 lines (20 loc) · 707 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
# coding: utf-8
# In[ ]:
def shell_sort(arr):
sublistcount = len(arr)/2
# While we still have sub lists
while sublistcount > 0:
for start in range(sublistcount):
# Use a gap insertion
gap_insertion_sort(arr,start,sublistcount)
sublistcount = sublistcount / 2
def gap_insertion_sort(arr,start,gap):
for i in range(start+gap,len(arr),gap):
currentvalue = arr[i]
position = i
# Using the Gap
while position>=gap and arr[position-gap]>currentvalue:
arr[position]=arr[position-gap]
position = position-gap
# Set current value
arr[position]=currentvalue