-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubble.py
43 lines (29 loc) · 967 Bytes
/
bubble.py
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
import timeit
class bubbleStringList:
def add(self, string):
st1 = self
st2 = string
split = string.split()
if split == '':
print("nothing stored")
else:
UserL = split
return UserL
def sort(self,astring):
choose = list(astring)
#print(choose)
for pass_n in range(len(choose) -1, 0, -1):
for i in range (pass_n):
if choose[i] > choose[i + 1]:
temp = choose[i]
choose[i] = choose[i + 1]
choose[i + 1] = temp
return choose
cd = bubbleStringList()
astring = '3', '5', '8', '9', '4'
print("the initial string is" , astring)
print("the string sorted is " , cd.sort(astring))
#t = timeit.Timer("bubble.sort(self, astring)", "import bubble")
#results = t.repeat(5,1000)
#for i, item in enumerate(results):
#print(i, "\t", item)