Python Program to Implement Bubble Sorting

01. Example:

def bubbleSorting(data):
    
    for i in range(len(data) - 1, 0, -1):
        flag = True
        
        for j in range(0, i):
            if data[j + 1] < data[j]:
                data[j], data[j + 1] = data[j + 1], data[j]
                flag = False
        
        if flag:
            return
 
 
list01 = input('Enter the list of numbers: ').split()
list01 = [int(x) for x in list01]

bubbleSorting(list01)

print('nSorted list: ', end='')
print(list01)

Output:

Enter the list of numbers: 320 420 140 500 185 60 200 80 10 100
Sorted list: [10, 60, 80, 100, 140, 185, 200, 320, 420, 500]

 

Leave a comment