+ 2
Input a list, sort it using bubble sort and print the sorted even elements before the sorted odd elements in a single list.
I have written up a code for this and it doesn't seem to work and just seems overly complicated is there a better way to do this. Eg of the code should work Input: [2,8,6,5,3] Output: [2,6,8,3,5] https://code.sololearn.com/c46i4iPPOFSe/?ref=app
4 Respuestas
+ 2
It took time to understand your logic but I have fixed it. The main problem was that you were comparing indexes of the list instead of values at that index
# I have written corrections made in comments
# if you still have some doubts then you can ask me anytime
https://code.sololearn.com/cmOPn84XgMXg/?ref=app
+ 2
In the attached file you can find 2 other ways to solve this task.
https://code.sololearn.com/c6HPj1QI8OpI/?ref=app
+ 1
Arsenic thanks you, I understood the code. I think I need to focus more while coding and revisit Booleans.
+ 1
Lothar the main thing I was stumbling on wasn't the problem itself but I had to do it using bubble sort but thanks anyways.