Quick actions

cmd+k|ctrl+k

Navigation

Languages

bubble sort

Snippet info

Language

Python

Visibility

public

Author

jack98765.2007

Created

2024-06-18T15:44:35.341964Z

Updated

2024-06-18T15:44:35.341964Z

def bubble_sort(lst):
    sorted_ = False
    while not sorted_:
        sorted_ = True
        for i in range(len(lst) - 1):
            print(*lst)
            print('  ' * i + '^ ^')
            if lst[i] > lst[i + 1]:
                sorted_ = False
                lst[i], lst[i + 1] = lst[i + 1], lst[i]
                print(*lst)
                print('  ' * i + '^ ^')

bubble_sort([1, 3, 2, 5, 4, 8, 9, 7, 6, 0])
INFO