Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Shell sort/Shell sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def shellsort(MyList):
n = len(MyList)
gap = n // 2
while gap > 0:
for i in range(gap,n):
temp = MyList[i]
j = i
while j >= gap and MyList[j-gap] > temp:
MyList[j] = MyList[j-gap]
j = j - gap
MyList[j] = temp
gap = gap // 2

def PrintList(MyList):
for i in MyList:
print(i, end=" ")
print("\n")

MyList = [10, 1, 23, 50, 4, 9, -4]
print("Original List")
PrintList(MyList)

shellsort(MyList)
print("Sorted List")
PrintList(MyList)