-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellSort.py
More file actions
24 lines (19 loc) · 730 Bytes
/
Copy pathshellSort.py
File metadata and controls
24 lines (19 loc) · 730 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
#shell sort
def shellSort(alist):
sublistcount = len(alist)//2
while sublistcount > 0:
for startposition in range(sublistcount):
gapInsertionSort(alist, startposition, sublistcount)
print("After increments of size",sublistcount,"The list is",alist)
sublistcount = sublistcount // 2
def gapInsertionSort(alist,start,gap):
for i in range(start+gap,len(alist),gap):
currentvalue = alist[i]
position = i
while position >= gap and alist[position-gap] > currentvalue:
alist[position] = alist[position-gap]
position = position-gap
alist[position] = currentvalue
alist = [54,26,93,17,77,31,44,55,20]
shellSort(alist)
print(alist)