Created
May 25, 2020 14:22
-
-
Save jigi-33/22ea4fd609024079357619ae1119bbd7 to your computer and use it in GitHub Desktop.
Сортировка пузырьком
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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