Quick actions

cmd+k|ctrl+k

Navigation

Languages

Bubble Sort by Moin

Snippet info

Language

Python

Visibility

public

Author

moin778866.ma

Created

2022-07-21T19:16:47.515861Z

Updated

2022-07-21T19:16:47.515861Z

# bubble sort has a slight advantage over selection sort, it takes the advantage of data if it becomes more sorted while sorting 
# It has better best case scenario complexity than selection sorting
# We sort the adjacent numbers again and again till our array becomes sorted.

arr = [4,6,8,2,7,5,0] #7
length = len(arr)
for j in range(length-1):
    for i in range(length-1):
        if arr[i] > arr[i+1]:
            arr[i], arr[i+1] = arr[i+1], arr[i]
    print(arr)
INFO