Python Implementation

suggest change
def bubble_sort(values: list[int]) -> None:
    """Sort values in place using bubble sort."""
    for end in range(len(values) - 1, 0, -1):
        swapped = False
        for index in range(end):
            if values[index] > values[index + 1]:
                values[index], values[index + 1] = values[index + 1], values[index]
                swapped = True
        if not swapped:
            break


values = [10, 1, 2, 11]
bubble_sort(values)
print(values)
[1, 2, 10, 11]

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents