-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellSort.py
More file actions
33 lines (23 loc) · 831 Bytes
/
ShellSort.py
File metadata and controls
33 lines (23 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
###########################
# Author: Hemant Tripathi #
###########################
def main():
print('Starting Shell Sort program')
dataArray = [25, 57, 48, 37, 12, 92, 86, 33]
gap = int(len(dataArray)/2)
while gap > 0:
print('Gap = ', gap)
for i in range(gap, len(dataArray)):
tmp = dataArray[i]
print('i = '+str(i)+'; Temp Value : ', tmp)
j = i
while j >= gap and dataArray[j-gap] > tmp:
dataArray[j] = dataArray[j-gap]
j = j - gap
dataArray[j] = tmp
print('After iteration data array is : ', dataArray)
gap = int(gap/2)
print('################ Result #######################')
print('Shell Sorting completed. Result: ', dataArray)
if __name__ == "__main__":
main()