How to do bubble sort using python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to do bubble sort using python?

19th May 2020, 6:19 AM
ajaynath reddy
ajaynath reddy - avatar
10 Answers
+ 1
u know. why do you ask?
19th May 2020, 6:31 AM
Oma Falk
Oma Falk - avatar
+ 1
okay please LINK your code here even if buggy.
19th May 2020, 6:33 AM
Oma Falk
Oma Falk - avatar
+ 1
This is how I did it ,tho it wasn't really that easy as I thought it would be! I knew the logic but implementing it was a challenge!! https://code.sololearn.com/cETkoID3Q23o/?ref=app
19th May 2020, 7:03 AM
Abhay
Abhay - avatar
+ 1
This is a pretty standard bubble sort implementation. Used, Abhay list and a timer to show it may be faster. Which was already sorted for some reason. Just plug any number list into it. https://code.sololearn.com/cs6oVDhG8oOq/?ref=app
19th May 2020, 7:15 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
https://docs.python.org/3/library/timeit.html you can remove it if desired
19th May 2020, 7:32 AM
ChaoticDawg
ChaoticDawg - avatar
0
#python 3.7.1 def bubble(x): if a[len(a)-1]==max(a) and a[0]==min(a): print(a) return a else: i=0 while i<len(a)-1: a[i],a[i+1]=a[i+1],a[i] i=i+1 return bubble(x) a=[8,6,7,5,1] a=list(map(bubble,a)) Why error?
19th May 2020, 6:20 AM
ajaynath reddy
ajaynath reddy - avatar
0
It is giving error and I asked for any another way to do.
19th May 2020, 6:32 AM
ajaynath reddy
ajaynath reddy - avatar
0
Or modification
19th May 2020, 6:33 AM
ajaynath reddy
ajaynath reddy - avatar
0
What is the use of time in this?
19th May 2020, 7:31 AM
ajaynath reddy
ajaynath reddy - avatar