Tutorial on how to implement the BubbleSort sorting algorithm in Python 3 with animated demo and code implementation example.

PYTHON SORTING ALGORITHMS

► Insertion Sort

► Selection Sort

► Bubble Sort

► Merge Sort

► Quick Sort

► Code on GitHub

► Subscribe to my Channel

► Thank me on Patreon:

Nguồn:https://quydinh.com/

Xem Thêm Bài Viết Khác:https://quydinh.com/cong-nghe

Thank you sooo muchhhh!!!! Have my comp exam tomorrow!!! Really saved my life!!!!

That intro.. Omg 😂😂😂

0:01 Michael Buble sorted this video

Hey , but what is the "i" purpose here ? instead of for j in range(0, len(my_list) – 1 – i ) you could say just for j in range(i – 1) and then when you compare you could say if my_list[j] > my_list[i]: my_list[ j ], my_list[ i ] = my_list[ i ], my_list[ j ]. These gives me more hints about the function itself and have some logic , like j is the previous number and i is the next number to be compared to j.

Does it make sense ?

thanks my dude

HELLO

Typo at the start card

Buble

intro music made me jump from my seat

how does -1-i work

thx joe

the starting music gives the feeling of a movie 😀

Doesn't work

Bad algorithm

Everywhere it is "myList" but the actual array is "theList".

Thank you for the help!

Thanks Nicholas Cage

how would you do this if you did not know that the last number was correct

I have a question, if the list is incrementing negatively, how do we get the iterator to start from the left side of the list.

TypeError: '>' not supported between instances of 'int' and 'list' come up for me

Really awesome

You should post the code in the description 🙂 … I copied it down still. Just for future reference…

Add a public comment

Army. Green. Python. Extreme. Calm. Sleep.

Why – i in the j?

how do we sort in descending order?

def bubbleSort(myList):

for i in range (0, len(myList) – 1):

for j in range(0, len(myList) – 1 – i):

if myList[j] > myList[j+1]:

myList[j], myList[j+1] = myList[j+1], myList[j]

return myList

theList = ['b', 'd', 'f', 'a', 'c', 'e']

print(bubbleSort(theList))

Thank you so much. Very simple and easy explanation.

tnks man I got it

why -1 can any one explain

1:15 how to think of inner and outer loops

great video, it helped so much!

_sorted = False

while not _sorted:

_sorted = True

for i in range(len(a)-1):

if a[i] > a[i+1]:

a[i], a[i + 1] = a[i + 1], a[i]

_sorted = _sorted and False

else:

_sorted = _sorted and True

I did it think way. Isn't it necessary to jump back to the top of the loop because we can't be certain the the minimum value will be placed at index 0?

Hi,

Can you explain how the range() function takes for arguments in line 5 at 1:47? I thought it could only take 3 and they had to be separated by a comma; like this: range(start, stop, step)

Anyway well done, and very well explained