Code:
Note:- Scroll horizontally to see the full line of code.
def shell_sort(a,n):
# a is list to be sorted and n is the length of list
gap=n//2
p=1
while(gap>=1):
for i in range(gap,n):
current=a[i]
j=i-gap
while((a[j]>current) and j>=0):
temp=a[j+gap]
a[j+gap]=a[j]
a[j]=temp
j=j-gap
a[j+gap]=current
gap=gap//2
print("Pass",p,": ",a)
p=p+1
return a
Comments
Post a Comment