Advertisement
tanmoklepasha

Shell_sort

Nov 11th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. def shellSort(sample):
  2.     print("sample=",sample)
  3.     length = len(sample)
  4.     gap = int(length/2)
  5.     while(gap >= 1):
  6.         i = gap
  7.         while(i < length):
  8.             value = sample[i]
  9.             j = i
  10.             while(j-gap >= 0 and value < sample[j - gap]):
  11.                 sample[j] = sample[j - gap]
  12.                 j -= gap
  13.                 sample[j] = value
  14.             i+=1
  15.         gap = int(gap/2)
  16.     print("sorted sample=",sample)
  17.  
  18.  
  19. sample1 = [37,22,18,50,2,3,1,29,69,5]
  20.  
  21. shellSort(sample1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement