BUBBLE SORT
Repeatedly swaps adjacent out-of-order pairs,
letting larger values bubble toward the end.
TIME O(n²)
SPACE O(1)
Pronto para ordenar
bubble sort
1
def
bubble_sort
(a):
2
n =
len
(a)
3
for
p
in
range
(n -
1
):
4
swapped =
False
5
for
i
in
range
(n -
1
- p):
6
if
a[i] > a[i +
1
]:
7
a[i], a[i +
1
] = a[i +
1
], a[i]
8
swapped =
True
9
if not
swapped:
10
break
▶ Iniciar
↺ Reset
🔀 Baralhar pesos
🔊 Som: ligado
Volume
60%
Velocidade