Sort
The snippet can be accessed without any authentication.
Authored by
DATkachenko
Алгоритм сортировки(д/з)
snippetfile1.txt 339 B
from random import randint
N=5
A = [randint(1,100) for i in range(N)]
print("A = ", A)
def sort(A):
str = range(len(A) - 1)
while True:
for j in (str, reversed(str)):
swapped = False
for i in j:
if A[i] > A[i+1]:
A[i], A[i+1] = A[i+1], A[i]
swapped = True
if not swapped:
return A
B = sort(A)
print(B)
Please register or sign in to comment