-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertionSort.py
More file actions
28 lines (21 loc) · 826 Bytes
/
InsertionSort.py
File metadata and controls
28 lines (21 loc) · 826 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
###########################
# Author: Hemant Tripathi #
###########################
def main():
print('Starting program for Insertion Sort')
dataArray = [25, 57, 48, 37, 12, 92, 86, 33]
for i in range(1, len(dataArray)):
for j in range(i, 0, -1):
print('Comparing between : '+str(dataArray[j])+' and ', dataArray[j-1])
if dataArray[j] < dataArray[j-1]:
tmp = dataArray[j]
dataArray[j] = dataArray[j-1]
dataArray[j-1] = tmp
del tmp
else:
break
print('After next iteration, dataArray is: ', dataArray)
print('##################### Result ####################')
print('After Insertion Sort operation, Sorted array is: ', dataArray)
if __name__ == "__main__":
main()