Skip to content

Instantly share code, notes, and snippets.

@jigi-33
Created May 25, 2020 14:22
Show Gist options
  • Save jigi-33/22ea4fd609024079357619ae1119bbd7 to your computer and use it in GitHub Desktop.
Save jigi-33/22ea4fd609024079357619ae1119bbd7 to your computer and use it in GitHub Desktop.
Сортировка пузырьком
"""
Common 'Bubble' sorting ALGORITHM
"""
def bubble_sort(alist):
for i in range(len(alist) - 1, 0, -1):
no_swap = True
for j in range(0, i):
if alist[j + 1] < alist[j]:
alist[j], alist[j + 1] = alist[j + 1], alist[j]
no_swap = False
if no_swap:
return
alist = input('Enter the list of numbers: ').split()
alist = [int(x) for x in alist]
bubble_sort(alist)
print('Sorted list: ', end='')
print(alist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment