forked from ghostpye07/Python_projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSort comparison
More file actions
38 lines (38 loc) · 910 Bytes
/
Copy pathSort comparison
File metadata and controls
38 lines (38 loc) · 910 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
34
35
36
37
38
#Bubble Sort
def bubble_sort(a):
for x in range(0,len(a)-1):
for y in range(0,len(a)-1-x):
if a[y]>a[y+1]:
a[y],a[y+1]=a[y+1],a[y]
return a
def insertion_sort(a):
for x in range(1,len(a)):
tmp=a[x]
for y in range(x-1,-2,-1):
if tmp<a[y]:
a[y+1]=a[y]
else:
break
a[y+1]=tmp
return a
def printlist(a,tmp,val="General"):
print("resultant list by {} sort is".format(val))
print(*a)
print("time taken is {}".format(tmp))
def main():
from time import time
inp=[int(x) for x in input().strip().split()]
x=inp[:]
start=time()
bubble_sort(x)
end=time()
printlist(x,end-start,"Bubble")
y=inp[:]
start=time()
insertion_sort(y)
end=time()
printlist(y,end-start,"Insertion")
#driver code
#test
if __name__=='__main__':
main()