Listing 06-20: Sorting by the Bubble Sort method

##############################################################################
# Python From Scratch
# Autor: Nilo Ney Coutinho Menezes
# Editora Novatec (c) 2010-2024
# Site: https://pythonfromscratch.com
#
# File: listing\chapter 06\06.20 - Sorting by the Bubble Sort method.py
# Description: Sorting by the Bubble Sort method
##############################################################################

L = [7, 4, 3, 12, 8]
end = 5
while end > 1:
    changed = False
    x = 0
    while x < (end - 1):
        if L[x] > L[x + 1]:
            changed = True
            temp = L[x]
            L[x] = L[x + 1]
            L[x + 1] = temp
        x += 1
    if not changed:
        break
    end -= 1
for e in L:
    print(e)
Click here to download the file