bub_sort.py
To łatwe, wiem o tym ale nie mam niczego innego ciekawego do pokazania z pythona, coś napiszę lepszego jeszcze i będzie git.
This commit is contained in:
parent
bdaacbd9eb
commit
c017df8358
24
Bubble sort
Normal file
24
Bubble sort
Normal file
@ -0,0 +1,24 @@
|
||||
lstlen = int(input())
|
||||
lst = [int(x) for x in input().split()]
|
||||
|
||||
nr = True
|
||||
x = 0
|
||||
|
||||
while True:
|
||||
while x < ((lstlen) - 1):
|
||||
if lst[x] > lst[x + 1]:
|
||||
a, b = lst[x], lst[x + 1]
|
||||
lst[x], lst[x+1] = b, a
|
||||
x += 1
|
||||
nr = False
|
||||
else:
|
||||
x += 1
|
||||
if nr:
|
||||
break
|
||||
else:
|
||||
lstlen -= 1
|
||||
nr = True
|
||||
x = 0
|
||||
|
||||
for j in range(len(lst)):
|
||||
print(lst[j],end=" ")
|
Loading…
Reference in New Issue
Block a user