Browse Source

Merge pull request #3 from sunny3p/sortalgos

shell sort
pull/4/head
Sunny Patel 6 years ago
committed by GitHub
parent
commit
392c47c44d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 0 deletions
  1. +28
    -0
      sorting/shellSort.py

+ 28
- 0
sorting/shellSort.py View File

@ -0,0 +1,28 @@
# coding: utf-8
# In[2]:
alist = [54,26,93,17,77,31,44,55,20]
def shellSort(alist):
sublistcount = len(alist)//2
while sublistcount > 0:
for startposition in range(sublistcount):
gapInsertionSort(alist,startposition,sublistcount)
sublistcount = sublistcount // 2
return alist
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
print(shellSort(alist))

Loading…
Cancel
Save