# Title: Bubble sort
# Heading: Python Program for Bubble Sort
# Level: beginner
# Tags: sorting, bubble sort, swap, list
# Time: O(n²)
# Space: O(1)
# About: Sorts a list by swapping neighbours that are out of order, pass after pass, and stops early once a pass makes no swaps.

def bubble_sort(items):
    """Sort items in place, from smallest to largest."""
    n = len(items)
    for i in range(n - 1):
        swapped = False
        # The last i items are already in their places
        for j in range(n - 1 - i):
            if items[j] > items[j + 1]:
                items[j], items[j + 1] = items[j + 1], items[j]
                swapped = True
        if not swapped:
            break  # a pass with no swaps: the list is sorted


numbers = [25, 12, 90, 11, 34, 22, 64]
print("Before:", numbers)
bubble_sort(numbers)
print("After: ", numbers)
