You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
788 B
Python
26 lines
788 B
Python
def shellSort(alist):
|
|
sublistcount = len(alist)//2
|
|
while sublistcount > 0:
|
|
for start_position in range(sublistcount):
|
|
gap_InsertionSort(alist, start_position, sublistcount)
|
|
|
|
print("After increments of size",sublistcount, "The list is",nlist)
|
|
|
|
sublistcount = sublistcount // 2
|
|
|
|
def gap_InsertionSort(nlist,start,gap):
|
|
for i in range(start+gap,len(nlist),gap):
|
|
|
|
current_value = nlist[i]
|
|
position = i
|
|
|
|
while position>=gap and nlist[position-gap]>current_value:
|
|
nlist[position]=nlist[position-gap]
|
|
position = position-gap
|
|
|
|
nlist[position]=current_value
|
|
|
|
|
|
nlist = [14,46,43,27,57,41,45,21,70]
|
|
shellSort(nlist)
|
|
print(nlist) |