-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble.py
More file actions
81 lines (73 loc) · 1.78 KB
/
Copy pathbubble.py
File metadata and controls
81 lines (73 loc) · 1.78 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Optimised bubble sort for sortin values
list = [24,24,24,24,245,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24]
list1 = [27,84,64,24,245,249,424,124,94,56,47,67,32,31,765,453,398,825,77,73,14,39,43,34]
print ("List: ",list)
print ("List1: ",list1)
item = 1
for i in list:
try:
temp = list[item]
except IndexError as error:
print ("Length of List: ", item)
item += 1
lenoflist = item - 2
item = 1
for i in list1:
try:
temp = list1[item]
except IndexError as error:
print ("Length of List1: ", item)
item += 1
lenoflist1 = item - 2
item = 0
ite = 0
iterate = 0
incount = 1
count = 0
while incount > 0:
count += 1
ite = 0
incount = 0
if iterate > 0:
try:
temp = list[item+1]
except IndexError as error:
item = 0
print("Error")
while ite < lenoflist:
if list[ite] < list[ite+1]:
incount = 1
temp = list[ite]
list[ite] = list[ite+1]
list[ite+1] = temp
ite += 1
item = 0
iterate = 1
print ("Sorted List: ",list)
print ("Iterator run: ",count, "times")
item = 0
ite = 0
iterate = 0
incount = 1
count = 0
while incount > 0:
count += 1
ite = 0
incount = 0
if iterate > 0:
try:
temp = list1[item+1]
except IndexError as error:
item = 0
print("Error")
while ite < lenoflist1:
if list1[ite] < list1[ite+1]:
incount = 1
temp = list1[ite]
list1[ite] = list1[ite+1]
list1[ite+1] = temp
ite += 1
item = 0
iterate = 1
print ("Sorted List1: ", list1)
print ("Iterator run: ",count, "times")